swift - How to set an action to a part of UILabel? -


i'd set action "part" of uilabel not of uilabel, "term of service" of attached picture. using storyboard. now, i'm thinking cover uibutton on part of uilabel. however, troublesome adjust part of label button @ layout(iphone 5, 6 , 6 plus) autolayout. if know better way, please tell me. thank kindness.

enter image description here

i'd recommend using uitextview nsattributedstring. range of text looking for, , add button subview view.

nsrange termsofservicerange = [self.termsofusetextview.text rangeofstring:@"terms of service"]; self.termsofusetextview.selectedrange = termsofservicerange; uitextrange *termsofservicetextrange = [self.termsofusetextview selectedtextrange]; cgrect termsofserviceframe = [self.termsofusetextview firstrectforrange:termsofservicetextrange]; cgrect convertedframe = [self.view convertrect:termsofserviceframe fromview:self.termsofusetextview];  uibutton *termsofservicebutton = [[uibutton alloc]initwithframe:convertedframe]; [termsofservicebutton setbackgroundcolor:[uicolor clearcolor]]; [termsofservicebutton addtarget:self action:@selector(termsofservicebuttonpressed:) forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:termsofservicebutton]; [self.view bringsubviewtofront:termsofservicebutton]; 

Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -