繁体   English   中英

无法更改UILabel.titleLabel.text

[英]can't change the UILabel.titleLabel.text

奇怪的问题,我试图设置titleLabel.text,但它不会从默认标题文本更改。 我已经在调试器中逐步进行了检查,并检查了taskTitle值,该值正确是新值,但是titleButton.titleLabel.text属性似乎没有接受值分配。

- (void)setChallengeTitle:(NSString *)taskTitle
{
    titleButton.titleLabel.text = taskTitle;
    titleButton.titleLabel.font = [UIFont fontWithName:@"Gotham Bold" size:18];



    CGSize stringsize = [taskTitle sizeWithFont:[UIFont fontWithName:@"Gotham Bold" size:18]];
    //I have to add a little bit since it doesn't seem to calculate the size of gotham correctly
    int buttonWidth = stringsize.width + 20;
    if (buttonWidth > 320)
        buttonWidth = 320;

    [titleButton setFrame:CGRectMake( (320 - buttonWidth)/2 ,10, buttonWidth, 40)];
}

您是否尝试过通过方法设置UIButton的文本?

尝试:

[titleButton setTitle:taskTitle forState:UIControlStateNormal]

UIControlStateNormal将设置所有状态的标题。

如果显示默认文本,则可能意味着它未正确连接为IBOutlet。

在界面构建器中检查您的链接。

希望能帮助到你..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM