简体   繁体   English

使用自动布局将UIButton添加到自定义单元格

[英]Adding UIButton to custom cell with auto layout

I am trying to add a button through IB in a custom cell at top right corner of the cell. 我正在尝试通过IB在该单元右上角的自定义单元中添加一个按钮。 I am using auto layout to position it correctly but in simulator I don't know why the button wont show up. 我正在使用自动布局将其正确放置,但是在模拟器中我不知道为什么按钮不会显示。

But if i create it programmatically then it shows up perfectly. 但是,如果我以编程方式创建它,那么它会完美显示。

So my question is how can achieve it using IB and where i am doing it wrong. 所以我的问题是如何使用IB以及我做错了什么。

I have added four constraints on my button leading and trailing space to superview and fix width and height. 我在按钮的前导和尾随空格上添加了四个约束,以查看和固定宽度和高度。

Remove leading space constrain and add fix to top space constrain . 删除leading space constrain并修复top space constrain I mean there will be total 4 constrains Fixed width, height and fixed trailing, top space to super view and it will work. 我的意思是说,总共有4个约束。固定宽度,高度和固定拖尾,顶部空间才能观看,它将起作用。 If it is not working means you have not set your tableView constrains. 如果不起作用,则表示您尚未设置tableView约束。 For tableView fix it from top,bottom,left and right space from super view. 对于tableView,请从超级视图的顶部,底部,左侧和右侧空间对其进行修复。

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

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