故事板+ UIcollectionView:Ui在iOS模拟器和设备上的显示方式不同

时间:2014-09-26 14:29:44

标签: ios xcode uicollectionview uistoryboard

我正在尝试使用Stroyboards在Xcode 6上为iPhone5,5c,5s和6制作应用程序,但我遇到了一个问题。

我正在使用带有自定义UICollectionViewCell的UICollectionView以及单元格中包含的另一个自定义视图。

问题在于,当我查看故事板然后我看到我需要的东西时,我在iOS模拟器中运行应用程序并且UI看起来很好但是当我在iPhone 5c上测试相同的应用程序时,UI大部分都是空白的。 / p>

这是来自模拟器的图像:

enter image description here

这就是我在iPhone上得到的结果:

iPhone 5c Screenshot

各个项目是UIViewControllerCell子类的对象。

模拟器屏幕截图中的图像是UIView(包含在UICollectionViewCell中),它根据我提供给它的图像数量来设置图像的帧。因此,如果我有1,那么它将显示在为第一个项目指定的图像的完整区域中,如果有超过4个图像,则可以显示最多4个图像,然后有一个标签代替第四个图像。

对我来说真的很奇怪的是,在iPhone 5c上,UI只显示一个图像,所以至少UiCollectionView单元格是可见的,但是再一次,单元格也有白色背景颜色,为什么没出现? 这是子类UICllectionViewCell的drawRect方法中的cod:

-(void)drawRect:(CGRect)rect {    
self.contentView.layer.cornerRadius = 3.0f;
self.contentView.layer.borderWidth = 0.25f;
self.contentView.layer.borderColor = [UIColor clearColor].CGColor;
self.contentView.backgroundColor = [UIColor whiteColor];
self.contentView.layer.masksToBounds = YES;

self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(0, 0.5f);
self.layer.shadowRadius = 3.0f;
self.layer.shadowOpacity = 0.125f;
self.layer.masksToBounds = NO;
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.contentView.layer.cornerRadius].CGPath;

}

我尝试过玩约束但没有发生任何事情,我把autolayout关闭了,但仍然没有。

有人可以指出错误和修正吗?

谢谢

编辑1:

我将self.contentView.frame = self.frame;添加到drawRect的顶部,这就是结果:

self.contentView.frame = self.frame

这是我用来加载图片的代码,这是在sublcassed UICollectionViewCell中:

-(void) populate:(dataObject *) dataObject

{

NSArray *thumbsArray = dataObject.thumnails;
_thumbnailsView = [[ThumbnailsView alloc] initWithFrame:CGRectMake(0, 0, 139, 107)];
_tempThumbnailsView = [[ThumbnailsView alloc] initWithFrame:CGRectMake(0, 0, 139, 107)];
[_tempThumbnailsView setBackgroundColor:[UIColor blueColor]];
_tempThumbnailsView.fileCount = bucket.fileCount;
_tempThumbnailsView.thumbnailsArray = thumbsArray;

[self.thumbnailsViewArea addSubview:_tempThumbnailsView];

self.title.text = dataObject.name;

}

" self.thumbnailsViewArea"是单元格中包含图像的视图的IBOutlet。

1 个答案:

答案 0 :(得分:0)

检查自动布局属性。