Search code examples
iphoneiosuibuttonalignment

ios: Centering programmatically edited content in UIButton


I have a UIbutton with some centered text in it. When I programmatically update the text, using: button.titleLabel.text = newValue; it is no longer centered, instead it has a very strange position (nor centered, nor left-aligned)... how can i make the button update the text to be centered horizontally?


Solution

  • The title of a UIButton should be set using the setTitle:forState: method.