iphone - Why doesn't UIButton title display? -
In the viewDidLoad method of a UIViewController, I do this:
UIButton * b = [[UIButton Type UIButtonTypeRoundedRect] with initWithFrame: CGRectMake (0, 0, 100, 100)]; [B SETITAL: @ State for "Testing": UICOnlineStateNational]; [BitTitLarroller: [UIColor blackcolor] forState: UIControlStateNormal]; [Self.view addSubview: b]; // Edit: 'B' must be NSLog (@ "button title:% @", [b titleLabel] .text);
Button does not display but display title The "test" for the NSLog line console prints. Any suggestions on what I'm doing wrong? I can not tell you why this does not work, but I have a solution:
UIButton * b = [UIButtonTypeRoundedRect] with UIButton Button; B. Frame = CGRactam (0, 0, 100, 100); [B SETITAL: @ State for "Testing": UICOnlineStateNational]; [BitTitLarroller: [UIColor blackcolor] forState: UIControlStateNormal]; [Self-add subview: b];
Separating the frame with the allocation of the button and init.