【发布时间】:2016-02-27 15:10:09
【问题描述】:
我想在用户触摸单元格时更改边框颜色。我的 UICollectionView 中有以下代码,但它不起作用:
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.user["avatar"] = self.avatars[indexPath.row]
do {
try self.user.save()
} catch {
print(error)
}
//self.performSegueWithIdentifier("returnToProfile", sender: user)
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! AvatarViewCell
cell.layer.borderWidth = 5.0
cell.layer.borderColor = UIColor.yellowColor().CGColor
}
谢谢!
编辑:我在被标记为重复的问题中尝试了投票最多的答案,但它仍然不起作用。 cell.layer.borderColor = UIColor.yellowColor().CGColor 不会改变颜色。
也许这是我如何定义单元格的问题?
【问题讨论】:
-
我尝试了那个问题的答案,但仍然没有用。我认为这可能是我如何定义单元格的问题
-
您是否尝试更改内容视图的边框?
cell.contentView.layer.borderWidth = 1.0 cell.contentView.layer.borderColor = UIColor.yellowColor().CGColor
标签: ios swift uicollectionview swift2