簡體   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