我尝试以编程方式创建UIButton时遇到一些问题.问题是按钮显示(即,如果我设置背景颜色,我可以清楚地看到按钮)并且是可点击的,但标题标签不可见.
这是我正在做的事情:
valueButton = [UIButton buttonWithType:UIButtonTypeCustom];
[valueButton addTarget:self action:@selector(openList:) forControlEvents:UIControlEventTouchUpInside];
valueButton.frame = CGRectMake(160.0, decalageLabel+6.0, 120.0, 20.0);
[valueButton.titleLabel setTextAlignment:UITextAlignmentRight];
[valueButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Neue-Light" size:17.0]];
UIColor * colorLabelValue = [[UIColor alloc] initWithRed:131.0/255.0 green:159.0/255.0 blue:86.0/255.0 alpha:1.0] ;
[valueButton setTitleColor:colorLabelValue forState:UIControlStateNormal];
if(txtValueField == NULL){
txtValueField = @"";
}
valueButton.titleLabel.text = [NSString stringWithFormat:@"%@", txtValueField];
NSLog(@"button : %@ ", valueButton.titleLabel.text);
[self.contentView addSubview:valueButton];
Run Code Online (Sandbox Code Playgroud)
哦,我确保标题有一个实际值,通过NSLogging它的文本值,这很好.所以我不知道发生了什么.任何的想法?
不要[[button titleLabel] setTitle:]用于此.使用[button setTitle:@"blah" forControlState:UIControlStateNormal].
这允许您为突出显示,选定,向上等设置不同的标题.
| 归档时间: |
|
| 查看次数: |
1517 次 |
| 最近记录: |