c# - 自定义 UITableViewCell 宽度问题

标签 c# ios iphone xamarin xamarin.ios

我有一个带有 .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/

相关文章:

ios - 如何在 GMS map 上绘制新标记(带有已绘制的标记)并选择设置?

ios - 单击 tableView 单元格时保留 tabController 的已加载 View 部分?

c# - 在 C# 中,为什么我会收到 "can' t cast double to float 错误”?

c# - 将 Nullable<DateTime> 序列化为 XML

c# - 在 C# 中解压缩 JPEG 图像的最快方法是什么

iPhone读/写.plist文件

iphone - iPhone中的下载队列

c# - C#应用程序如何调用java应用程序

iOS 低功耗蓝牙未检测到外设

iphone - Xamarin iTunes 附属链接