ios - Make only part of a sentence a link (add selector) -


so trying implement following. have view, has sentence. part of sentence links view. looks like:

i cat. learn more 

the learn more link (blue in color), when clicked open view.

currently using uilabel write "i cat". realize best way add selectors use button, "learn more" should button?

is there way write sentence out without using 2 different uicomponents?

if not, how make uilabel , uibutton horizontally aligned each other?

the following code label in -layoutsubviews:

cgsize labelsize = [_label.text sizewithfont:_label.font constrainedtosize:bounds.size linebreakmode:_label.linebreakmode];   _label.frame = cgrectmake(0, 0, bounds.size.width - kmarginfortext, labelsize.height);   _label.center = cgpointmake(horizontalcenter, cgrectgetmaxy(_previouslabel.frame) + kdistancebetweenpreviousandcurrentlabel); 

and code label itself.

    _label = [[uilabel alloc] initwithframe:cgrectzero];     _label.text = "i cat";     _label.font = [uifont systemfontofsize:14];     _label.textalignment = nstextalignmentcenter;     _label.numberoflines = 0;     _label.linebreakmode = uilinebreakmodewordwrap;     [self addsubview:_label]; 

any appreciated!

to answer question single uicomponent, use uilabel in conjunction uitapgesturerecognizer create intended effect. granted make whole label tappable... having bigger tap target area never bad thing.

in particular use nsattributedstring set label text (nsattributedstring change color @ end of string):

uilabel *label = [[uilabel alloc] init]; //use initwithframe or setup constraints after initialization here label.attributedtext = (your nsattributed string here) 

then initialize tap recognizer onto uilabel this:

uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(userdidtaplearnmore)]; label.userinteractionenabled = yes; [label addgesturerecognizer:tap]; 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -