繁体   English   中英

UIButton标题没有出现

[英]UIButton title doesn't show up

我尝试以编程方式创建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];

哦,我确保标题有一个实际值,通过NSLogging它的文本值,这很好。 所以我不知道发生了什么。 任何想法?

不要使用[[button titleLabel] setTitle:] 使用[button setTitle:@"blah" forControlState:UIControlStateNormal]

这允许您为突出显示,选定,向上等设置不同的标题。

暂无
暂无

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

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