自定义UITableViewCell宽度问题

时间:2015-04-30 15:50:32

标签: 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

3 个答案:

答案 0 :(得分:1)

单元格的tableview总是宽度为320,表示表格没有响应屏幕大小。您需要做的是检查表视图的自动布局约束是否设置正确(如果您正在使用自动布局),或者是否为每个屏幕大小设置不同的表视图框架。

答案 1 :(得分:0)

Bounds.Width

iPhone 4S& 5,375为iPhone 6和414为iPhone 6 +。

你看到宽度为320的事实,让我相信你的应用程序还不支持更高密度的屏幕,并将扩大320。你可以看出,状态栏(顶部的时间)会略大一些。

为每个设备尺寸设置相应的启动图像,并且所有设备都将以原始分辨率运行。

您需要按以下分辨率设置启动图像:

Default-667h@2x.png for iPhone 6; dimensions 750x1334
Default-736h@3x.png for iPhone 6 Plus; dimensions 1242x2208

答案 2 :(得分:0)

尝试使用layoutSubviews方法获取宽度。

override func layoutSubviews() {
    super.layoutSubviews()

    NSLog("self.frame.size is %@", NSStringFromCGSize(self.frame.size))
}
下面的

是我的输出

  

2015-07-21 10:10:3​​4.942 MyApp [74669:1208599] self.frame.size是{768,310}

相关问题