【发布时间】:2016-09-01 13:53:42
【问题描述】:
我自定义了包含UILabel 和UIImage 的UICollectionViewCell。
我想将单元格设置为循环格式。
注意:- sizeForItemAtIndexPath 由于自动布局,无法更改。
下面是我用过的代码:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,sizeForItemAtIndexPath indexPath:NSIndexPath ) -> CGSize {
return CGSize(width: (self.objKeypadCollectionView.frame.size.width/3)-10, height: (self.objKeypadCollectionView.frame.size.height/4)-10)
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let objKeypadCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("idKeypadCollectionViewCell", forIndexPath: indexPath) as! KeypadCollectionViewCell
if (self.numberArray[indexPath.item])=="asda" {
objKeypadCollectionViewCell.lblNumber.text = ""
objKeypadCollectionViewCell.imgPrint.hidden = false
}
else if (self.numberArray[indexPath.item])=="Derterel" {
objKeypadCollectionViewCell.lblNumber.text = self.numberArray[indexPath.item]
objKeypadCollectionViewCell.imgPrint.hidden = true
}
else {
objKeypadCollectionViewCell.imgPrint.hidden = true
objKeypadCollectionViewCell.lblNumber.text = self.numberArray[indexPath.item]
objKeypadCollectionViewCell.layer.borderColor = UIColor.lightGrayColor().CGColor
objKeypadCollectionViewCell.layer.borderWidth = 1
objKeypadCollectionViewCell.layer.cornerRadius = objKeypadCollectionViewCell.frame.size.width/2
}
return objKeypadCollectionViewCell
}
【问题讨论】:
-
它的图像或按钮或collectionview单元格
-
好吧,如果你真的不能改变你的
sizeForItemAtIndexPath实现,那么实现你想要的最简单的方法是向你的单元格添加一个虚拟矩形视图并在其上设置你的边框和角半径. -
你为什么不简单地改变键盘类型来做到这一点?
-
@Anbu.Karthik : 这是一个标签,其cornerRadius被设置为圆形
-
@Desdenova : 没找到你
标签: ios swift xcode uicollectionview uicollectionviewcell