UIButton with CAShapeLayer makes title disappear while scrolling

限于喜欢 提交于 2020-01-06 16:26:06

问题


I have a ProfileCollectionViewCellwith 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!