【问题标题】:UIButton text not displayingUIButton文本不显示
【发布时间】:2015-01-09 15:17:49
【问题描述】:

我在表格单元格上有一个UIButton。我正在尝试设置它的文本,但它没有显示它。

UIButton *btnName = [[UIButton alloc]init];
btnName.frame = CGRectMake(0.0, imgPic.frame.origin.y+imgPic.frame.size.height+10.0, self.frame.size.width, 20.0);
btnName.center = CGPointMake(cell.contentView.center.x, imgPic.frame.origin.y+imgPic.frame.size.height+10.0);
btnName.titleLabel.text = [@"Nitin" uppercaseString];
//[btnName setTitle:[@"Nitin" uppercaseString] forState:UIControlStateNormal];
[cell.contentView addSubview:btnName];

【问题讨论】:

  • 尝试设置 UIButton 的 BackgroundColor 并检查 visible 是否在 Cell 中。?
  • 尝试像这样创建按钮对象UIButton *btnName = [UIButton buttonWithType:UIButtonTypeCustom];
  • @AbhishekSharma :我将背景颜色设置为蓝色并且按钮出现了。但不是文字。
  • 我可以知道投反对票的原因吗?

标签: ios iphone uibutton


【解决方案1】:

找到解决办法:

UIButton *btnName = [UIButton buttonWithType:UIButtonTypeRoundedRect];  

也用

[btnName setTitle:[@"Nitin" uppercaseString] forState:UIControlStateNormal];  

改为。

请看Christien's的回答。

【讨论】:

    【解决方案2】:

    可能与将按钮添加到单元格有关。尝试将其颜色设置为蓝色或红色以检查其是否可见。还要检查按钮框架的最终宽度和高度是否非零,并且它的坐标是否在单元格内。

    【讨论】:

      猜你喜欢
      • 2011-11-30
      • 2020-03-11
      • 2012-11-29
      • 2014-06-16
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2012-04-01
      • 2020-10-30
      相关资源
      最近更新 更多