问题
I have a ProfileCollectionViewCell
with one method:
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)
}
And just after load it looks like this:
but after I scroll my title (heart from icomoon font) disappear:
Why?
回答1:
I solved the problem, replacing:
likeButton.layer.addSublayer(shapeLayer)
with
likeButton.layer.insertSublayer(shapeLayer, below: likeButton.titleLabel?.layer)
来源:https://stackoverflow.com/questions/38218283/uibutton-with-cashapelayer-makes-title-disappear-while-scrolling