带有 CAShapeLayer 的 UIButton 使标题在滚动时消失

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)