我有一个带有 .xib 的自定义 UITableViewCell。在 xib 中,我将单元格宽度设置为 320。
我想在单元格内相对于单元格宽度放置一个 UIlabel。但是,在运行时的代码中,单元格的 Bounds.width 始终为 320(如 xib 中设置),而不是我需要正确定位 UILabel 的屏幕/UITableView 的实际宽度。
显然,iPhone 5、6 和 6+ 的宽度应该有所不同,至少在运行时是这样,但在所有设备上它始终设置为 320。我错过了什么?
谢谢!
编辑
这是一小段代码。
var newFrame = _lblDetail.Frame;
newFrame.X = Bounds.Width - 55; //get current width of cell, and subtract 55 and set that as the X value of the frame for the label
_lblDetail.Frame = newFrame; //set new frame on label
最佳答案
单元格的 tableview 始终具有 320 的宽度表明表格不响应屏幕尺寸。然后你需要做的是检查你的表格 View 的自动布局约束是否设置正确(如果你使用自动布局)或者表格 View 的框架是否针对每个屏幕尺寸设置不同。
关于c# - 自定义 UITableViewCell 宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29972318/