[英]Custom UICollectionViewCell
I have a custom UICollectionViewCell with an oval(with a border) and a label. 我有一个带有椭圆(带有边框)和标签的自定义UICollectionViewCell。 The cell will change its size based on the size of the label.
单元格将根据标签的大小更改其大小。
Why does my view get warped? 为什么我的观点会扭曲?
GOAL 目标
1. create a prototype cell in Interface builder with a subclass of UIView with grey border. 1.在“界面”构建器中使用带有灰色边框的UIView的子类创建原型单元。 It has top, bottom, trailing, & leading constraint constant of 4.
它的顶部,底部,尾部和前部约束常数为4。
2. I add label (not subview of bordered view explained above) with top, bottom, trailing, & leading constraint constant of 8. 2.添加顶部,底部,尾随和前导约束常数为8的标签(不是上面说明的带边框视图的子视图)。
3. I add IBOutlet of collectionViewFlowLayout so I can set estimated size (this is for cell resizing). 3.我添加了collectionViewFlowLayout的IBOutlet,以便可以设置估计的大小(这是用于调整单元格的大小)。
collectionViewFLowLayout.estimatedItemSize =
collectionViewFLowLayout.estimatedItemSize =
UICollectionViewFlowLayoutAutomaticSizeUICollectionViewFlowLayoutAutomaticSize
4. The rest is boilerplate like conforming to UICollectionViewDataSource 4.其余的样板都遵循UICollectionViewDataSource
Here is Custom view class. 这是自定义视图类。
class CustomView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1
self.layer.cornerRadius = self.frame.height / 2
self.clipsToBounds = true
}
}
Your corner radius is little too much, try decreasing it. 您的拐角半径太小,请尝试减小它。 This,
这个,
self.frame.height / 2
seems to be a wrong proportion, try increasing the denominator /3,/4 etc. 似乎是错误的比例,请尝试增加分母/ 3,/ 4等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.