iPhone/iPad UIButton TitleLabel text not appearing

Ian Vink picture Ian Vink · Mar 7, 2010 · Viewed 53.8k times · Source

I created a grid of buttons. The following code creates the buttons and displays them, but there is no text on the button. Is there a setting I am missing? (Obj-C replies are fine, I'm bi-lingual)

RectangleF frame = new RectangleF (X + 3, Y + 3, cellWidth - 2, cellHeight - 2);
UIButton button = new UIButton (frame);
button.TitleLabel.Text = "Baha'i";
button.TitleLabel.Font = UIFont.FromName ("Helvetica-Bold", 15);
button.TitleLabel.TextColor = UIColor.Black;
button.TitleLabel.Frame = frame;
button.BackgroundColor = UIColor.FromWhiteAlpha(.5f,.5f);
this.AddSubview (button);

Answer

Tobias Cohen picture Tobias Cohen · Mar 7, 2010

I think you want setTitle: forState:

[button setTitle:@"Baha'i" forState:UIControlStateNormal]