2016-07-06 55 views
0

我有一個ProfileCollectionViewCell一個方法:的UIButton與CAShapeLayer使標題消失時滾動

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) 
} 

而就在加載後,它看起來是這樣的:

enter image description here

但之後,我滾動我的頭銜(來自icomoon字體的心)消失:

enter image description here

爲什麼?

+0

打印'likeButton.frame',看看發生在滾動,或有什麼問題你重用 –

+0

我解決問題......圖層覆蓋了我的'titleLabel'。:) –

回答

1

我解決了這個問題,替換:

likeButton.layer.addSublayer(shapeLayer) 

likeButton.layer.insertSublayer(shapeLayer, below: likeButton.titleLabel?.layer)