[英]Change text color of UILabel inside Custom UICollectionViewCell
[英]Cannot change the frame of a UILabel in a Custom UICollectionViewCell
我正在制作一个Custom CollectionViewCell
,到目前为止一切顺利。
UIViewController
上具有UICollectionView
情节提要。 UICollectionViewCell
,上面具有该单元格的布局详细信息。 1)我认为它与Autolayout
,但是我不想关闭它,因为在项目的其余部分中都需要它。
2)请参考以下代码:
- (void)layoutSubviews { [super layoutSubviews]; UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation]; if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { _collectionLabel.frame = CGRectMake(20, 100, 280, 40); _collectionLabel.textColor = [UIColor blueColor]; _collectionLabel.backgroundColor = [UIColor clearColor]; } else { _collectionLabel.frame = CGRectMake(20, 20, 280, 40); _collectionLabel.textColor = [UIColor redColor]; _collectionLabel.backgroundColor = [UIColor clearColor]; } }
现在,上面的所有代码都可以正常工作,只是UILabel
的框架没有改变。 如果我为项目关闭了“自动Autolayout
”,那么它将起作用。
旋转设备时,我需要对上面的代码进行什么调整才能使单元格拾取框架变化? 其他一切正常-这是唯一的问题。 完成这项工作后,我便可以生产其余的单元格。
使用自动版式时,不应设置任何框架。 相反,您应该调整约束,或者在某些情况下,删除一些约束并添加其他约束。 最简单的方法是使IBOutlet适应IB中的约束,然后在代码中修改其常数值(讽刺的是,常数值是可以更改的约束的唯一参数)。 从您的问题尚不清楚,您想更改哪些框架参数,但是说您有一个名为leftCon的约束的出口,您可以像这样更改它,
self.leftCon.constant = 20;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.