ios - Align two different text on single line in iphone sdk -
i have uilabel
, uibutton
, text changing dynamic except uilabel
, want show them single label , should center align on single line both work differently show in picture underline text "the gluten free foodie" has clickable feature unlike text found by
. don't know how accomplish task if text of button in picture "the gluten free foodie" come long how can move label left show in picture. in advance.
try this:
nsstring *text1 = @"found "; //text of uilabel cgsize constraint1 = cgsizemake(320, 2000); //suppose total width of superview 320 cgsize size1 = [text1 sizewithfont:[uifont fontwithname:@"arialmt" size:12.0] constrainedtosize:constraint1 linebreakmode:uilinebreakmodewordwrap]; //font used in "found by" label nsstring *text2 = @"the gluten free foodie"; //text of uibutton cgsize constraint2 = cgsizemake(320, 2000); cgsize size2 = [text2 sizewithfont:[uifont fontwithname:@"arial-boldmt" size:12.0] constrainedtosize:constraint2 linebreakmode:uilinebreakmodewordwrap]; //font used in "the gluten free foodie" button float finalwidth = size1.width + size2.width + 2; float centerx = 320 - finalwidth; //suppose total width of view 320 centerx = centerx/2.0; lblfoundby.frame = cgrectmake(centerx, 20, size1.width, size1.height); btnthe.frame = cgrectmake(centerx + size1.width + 2, 20, size2.width, size2.height);
- find width of label based on text of label
- find width of button based on title of button
- get total width of label, button , space between these two.
- subtract total width uiview (superview of button , label) width (suppose 320).
- finally total space. after space divided 2.
- and last, based on set frame (x position important) of label , button.
Comments
Post a Comment