[英]Calling UIButton:setImage:forState makes button title disappear
[英]UIButton with CAShapeLayer makes title disappear while scrolling
我有一個ProfileCollectionViewCell
用一種方法:
func configureCellWithProfile(profile: Profile) {
shapeLayer.removeFromSuperlayer()
let path = CGPathCreateMutable()
CGPathMoveToPoint(path, nil, 0, 0)
CGPathAddLineToPoint(path, nil, CGRectGetWidth(likeButton.frame), 0)
CGPathAddLineToPoint(path, nil, CGRectGetWidth(likeButton.frame), CGRectGetHeight(likeButton.frame))
CGPathCloseSubpath(path)
shapeLayer.fillColor = profile.favourite ? UIColor.brilliantRose().CGColor : UIColor.blackSqueeze().CGColor
shapeLayer.path = path
likeButton.layer.masksToBounds = true
likeButton.layer.addSublayer(shapeLayer)
}
加載后,它看起來像這樣:
但是在我滾動標題(icomoon字體的心)后消失了:
為什么?
我解決了問題,替換為:
likeButton.layer.addSublayer(shapeLayer)
同
likeButton.layer.insertSublayer(shapeLayer, below: likeButton.titleLabel?.layer)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.