簡體   English   中英

帶有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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM