I have this
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(myAction:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:NSLocalizedString(@"Action", @"")
forState:UIControlStateNormal];
CGFloat width = button.bounds.size.width;
at this point width is zero…
zero?
any clues why?
Call
sizeToFiton your button after setting the title label. This will size it appropriately to the text you have just set.This gets called anyway on the button before it is drawn, but since you seem to need it earlier, you can do it yourself.