我定制了包含UILabel和UI
Image的UICollectionViewCell.
我想以圆形格式设置单元格.
我想以圆形格式设置单元格.
注意: – 由于AutoLayout,无法更改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 }