Check out the NSString
method -sizeWithFont:
. It returns a CGSize
that will inform you as to how much size your text will need in the button. Then you can adjust the button's frame based on this size, adding whatever padding you desire to the width and height of the button's frame. Something like this:
NSString *msg = @"The button label";
UIFont *font = [UIFont systemFontOfSize:17];
CGSize msgSize = [msg sizeWithFont:font];
CGRect frame = button.frame;
frame.size.width = msg.size.width+10;
frame.size.height = msg.size.height+10;
button.frame = frame;
(written from memory; not compiled. :-)
Of course, you have to set the button title and font as well...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…