如何增加内容视图的宽度,在元素之间添加一些空间边距并平均分布。下面是我尝试过的快速代码。
class EatTypeCell : UICollectionViewCell{
@IBOutlet weak var lblTitle: UILabel!
override func awakeFromNib() {
self.contentView.applyViewStyle(isRound: true, borderColor: UIColor.ColorGray, borderWidth: 1.5, backGroundColor: UIColor.ColorWhite)
self.lblTitle.applyStyle(labelFont: UIFont.applySemiBold(fontSize: 11.5), textColor: UIColor.ColorGray)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let height = collectionView.frame.height/2 - 14
var width : CGFloat = 0
if self.colEat == collectionView {
width = self.arrayMeal[indexPath.row].name.sizeOfString(font: UIFont.applySemiBold(fontSize: 11.5)).width + 50
}
return CGSize(width: width, height: height)
}