1

我试图设置 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)];
}
4

2 回答 2

1

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

尝试:

[titleButton setTitle:taskTitle forState:UIControlStateNormal]

UIControlStateNormal将为所有州设置标题。

于 2013-03-12T00:10:00.117 回答
0

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

在界面生成器中检查您的链接。

希望能帮助到你..

于 2013-03-11T23:56:43.670 回答