2016-07-06 4 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) 
Смежные вопросы