自定义表格视图单元格中UIButton的设置高度

问题描述 投票:0回答:1

我一直在制作“自定义表格视图”单元格,但是对于图像和按钮,无论何时创建一个,其高度似乎总是会填满单元格的高度,而所创建的任何框架都将被忽略。我认为我可能缺少明显的东西,但是在其他任何线程中都找不到答案。使用快速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)

enter image description here

swift uitableview uibutton
1个回答
0
投票

这与将UIButton添加到自定义表格视图的方式有关。您是否定义了任何锚点NSLayoutConstraint?

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

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

© www.soinside.com 2019 - 2024. All rights reserved.