I'm working on an iPhone app, and one of the buttons is supposed to have a text label on it that changes. When I set the text label programatically as seen below, it's shortened using '...' instead of displaying the full label -- even though there is ple开发者_JS百科nty of room for it on the button.
self.accuracyButton.titleLabel.text=@"User defined location";
I suspect this may be related by the way it 'resets' to the XIB defined 'accuracy' label whenever I try to click it, but I'm not sure how to fix it or what is going on.
please try
[button setTitle:@"foo" forState:UIControlStateNormal];
Yesterday I had the same issue, the button showed the three dots, even if there was enough room.
Using setTitle:forState:
instead of setting the property displayed the text correctly
You can change the amount of padding around the label by using this:
@property(nonatomic) UIEdgeInsets titleEdgeInsets
Not sure why it cuts off, but might I suggest simply using a UILabel over the top of the button? That allows much more refined control of the label boundary and size.
精彩评论