Alex Rivera | Logout

UIButton label text is being clipped

Asked 2011-01-01T23:39:11.633
46

I have a UIButton built in Interface Builder that has a default label. In Xcode, I'm changing the label text dynamically like so:

myButton.titleLabel.text = @"this is the new label";

However, when the text updates, the new string is being clipped down to the same size as the original string and ends up looking like:

this...label

Anyone know why this is happening?

Edit
Report

1 Answer

1

If that didn't work you can always determine the string size and adjust the button frame width. In that case you are sure it will fit.

// Calculate the size 
CGSize buttonSize = [@"My text.." sizeWithFont:[UIFont systemFontOfSize:15.0]
                    constrainedToSize:someSize lineBreakMode:UILineBreakModeWordWrap];

// Do whatever you want with the "buttonSize", you can for example adjust your button's frame width
answered 2011-01-04T00:37:55.983

Your Answer