开发者

UIButton's titleLabel.text is not displayed on Cocoa Touch

开发者 https://www.devze.com 2023-01-30 07:23 出处:网络
After I create a new UIButton at runtime, and set its titleLabel\'s text, the button\'s text is still not displayed.

After I create a new UIButton at runtime, and set its titleLabel's text, the button's text is still not displayed.

What am I doing wrong?

-(IBAction) cloneMe: (id) sender{

    if (!currentY) {
        currentY = [sender frame].origin.y;
    }

    UIButton *clone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CGRect cloneFrame = [sender frame];
    cloneFrame.origin.y += currentY + cloneFrame.size.height + 30;
    clone.frame = cloneFrame;
    [clone ti开发者_如何学PythontleLabel].text = @"I'm a clone";

    [[sender superview] addSubview:clone];

    currentY = cloneFrame.origin.y + cloneFrame.size.height;


}


You need:

[clone setTitle:@"I'm a clone" forState:UIControlStateNormal];

Check out the UIControl API docs for other valid values for the forState: argument.


Use setTitle:forState: to set the title of a button.

0

精彩评论

暂无评论...
验证码 换一张
取 消