2
我有几个属性的自定义UICollectionViewCell类:在自定义到的UIImageView添加覆盖UICollectionViewCell
class SimpleCollectionCell: UICollectionViewCell {
@IBOutlet weak var title_more: UILabel!
@IBOutlet weak var image_more: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var distance: UILabel!
@IBOutlet weak var activity: UIImageView!
}
我来填充数据的方法是这样:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! SimpleCollectionCell
var place = Place()
// set the current place
place = Places[indexPath.row]
// set the label
cell.title.text = place.title
// setup url
let url = NSURL(string: currentThing.imageUrl!)
// set the cell image
cell.activity.hnk_setImageFromURL(url!)
return cell
}
细胞呈现为它应该与显示为这样:
我的问题是如何让图像变暗?
我试图添加下面的代码在cellForItemAtIndexPath方法的底部,但它会变得越来越黑,因为它不断添加更多的子视图!
// Create a subview which will add an overlay effect on image view
let overlay: UIView = UIView(frame: CGRectMake(0, 0, cell.activity.frame.size.width, cell.activity.frame.size.height))
overlay.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3);
// Add the subview to the UIImageView
cell.activity.addSubview(overlay)
为什么不从xib文件创建单元格并在其中添加叠加视图? – Remover