【问题标题】:Setting height of UIButton in Custom Table View Cell在自定义表格视图单元格中设置 UIButton 的高度
【发布时间】:2020-04-17 08:38:19
【问题描述】:

我一直在制作自定义表格视图单元格,但是对于图像和按钮,每当我创建一个时,高度似乎总是填满单元格的高度,而创建的任何框架都将被忽略。我想我可能遗漏了一些明显的东西,但在任何其他线程中都找不到答案。使用 swift 5。

message = UIButton(frame: CGRect(x: 250, y: 350, width: 120, height: 10))
message.setTitle("Chat", for: .normal)
message.backgroundColor = .clear
message.layer.cornerRadius = 5
message.layer.borderWidth = 1
message.layer.borderColor = UIColor(red:0.97, green:0.71, blue:0.00, alpha:1.00).cgColor
message.titleLabel?.font = .systemFont(ofSize: 15)
message.setTitleColor(UIColor(red:0.68, green:0.07, blue:0.83, alpha:1.00), for: .normal)

【问题讨论】:

  • 你如何定义message
  • var message = UIButton()

标签: swift uitableview uibutton


【解决方案1】:

这与您将UIButton 添加到自定义表格视图的方式相关联。你定义了任何锚,NSLayoutConstraint吗?

如果是这样,您指定的框架将被定义的约束覆盖。

您能否提供将 UIButton 添加到 contentView 的方式?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    相关资源
    最近更新 更多