tags:

views:

31

answers:

3

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 plenty 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.

A: 

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.

XenElement
+1  A: 

You can change the amount of padding around the label by using this:

@property(nonatomic) UIEdgeInsets titleEdgeInsets
jlehr
Good answer; I was conflicted between yours and the one I chose because both of them are very good answers to my problem. The above one shows me the 'right' way to do it is why it won; but yours introduces new, useful information that will probably prove helpful on other problems.
RonLugge
+1  A: 

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

fluchtpunkt