Sunday, 15 April 2012

ios - Center a UIButton title in its frame -



ios - Center a UIButton title in its frame -

i want center (both x , y axis) + sign within uibutton cgrect keeps getting pushed downwards y-axis.

uibutton *abutton = [uibutton buttonwithtype:uibuttontypesystem]; [abutton settitle:@"+" forstate:uicontrolstatenormal]; [abutton.titlelabel setfont:[uifont fontwithname:@"helveticaneue-bold" size:(40.0)]]; [abutton setbackgroundcolor:[uicolor graycolor]]; [abutton settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal]; [abutton settitlecolor:[uicolor bluecolor] forstate:uicontrolstatehighlighted]; abutton.layer.cornerradius = 25.0; abutton.frame = cgrectmake(75.0, 100.0, 50.0, 50.0);

this more right if had ascenders , descenders. there's label within button , sized accommodate height of total range of possible characters of font. if don't position of label, you're free move it. there lot of ways this; might seek playing button's titleedgeinsets, example.

ios ios7 uibutton uilabel cgrect

No comments:

Post a Comment