ios - How to change the UILabel content by tapping? -


this question has answer here:

i add tap gesture on label couldn't retrieve tapped label in selector function. mean, example, function this:

-(void)changelabel:(uigesturerecognizer *)sender{} 

if gesture added on imageview, can imageview using sender.view.
since it's uilabel don't know , change text content.

hope question clear...

set interaction enabled, add would.

my example:

- (void)viewdidload  {     [super viewdidload];     self.mainlabel.text = @"this label";     uitapgesturerecognizer *taprecongizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(changetext)];     self.mainlabel.userinteractionenabled = yes;     [self.mainlabel addgesturerecognizer:taprecongizer]; }  -(void)changetext {     nsarray *randomnames = @[@"jim", @"bob", @"john", @"peter"];     self.mainlabel.text = [randomnames objectatindex:arc4random() % 4]; } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -