标题标签未显示UIButton

时间:2015-07-20 20:39:39

标签: ios objective-c iphone uibutton uilabel

我试图通过这样的数组设置UIButton文本:

// Set User Name
NSString *user = entry[@"user"][@"full_name"];
[cell.nameLabel.titleLabel setText:user];

但是,加载时应用程序上不会显示任何文本。正在返回文本并将其存储在数组中。这是我对Button的自定义:

// Name
self.nameLabel = [[UIButton alloc] initWithFrame:CGRectMake(58, 6, 192, 25)];
[self.nameLabel.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Regular" size:12.0]];
self.nameLabel.titleLabel.textColor = [UIColor colorWithRed:(38.0/255.0) green:(120.0/255.0) blue:(172.0/255.0) alpha:1.0];
[self.contentView addSubview:self.nameLabel];

2 个答案:

答案 0 :(得分:1)

[self.nameLabel setTitle:user forState:UIControlStateNormal];

答案 1 :(得分:0)

我想你已经得到了问题的答案。但是,如果您要寻找不同的内容,请尝试以下操作:is it possible to update UIButton title/text programmatically?