2017-06-05 5 views
1

セルフサイジングUILabelとシャドウを持つカスタムUITableViewCellがあります。自動サイズ変更のUITableViewCellシャドウがオフです

私は layoutSubviews()cellForRowAt: indexPathwillDisplay cellでこのコードを実装しようとしましたが、それは常にオフではなく中心である
class CustomCell: UITableViewCell { 

    @IBOutlet weak var titleLabel: UILabel! 
    @IBOutlet weak var cellBackgroundView: UIView! 
    @IBOutlet weak var creationDateLabel: UILabel! 

    override func layoutSubviews() { 
    super.layoutSubviews() 
    self.cellBackgroundView.layer.cornerRadius = 12 

    self.cellBackgroundView.layer.shadowColor = UIColor.black.withAlphaComponent(1.0).cgColor 
    self.cellBackgroundView.layer.shadowOffset = CGSize.zero 
    self.cellBackgroundView.layer.shadowRadius = 9 
    self.cellBackgroundView.layer.shadowOpacity = 0.8 
    self.cellBackgroundView.layer.shadowPath = UIBezierPath(rect: self.cellBackgroundView.bounds).cgPath 
    self.cellBackgroundView.layer.masksToBounds = false 
    self.cellBackgroundView.layer.shouldRasterize = true 

    self.cellBackgroundView.layer.rasterizationScale = UIScreen.main.scale 
    } 
} 

Shadow is not centered but off それを実装する正しい方法は何ですか?

編集:これは、tableViewでスクロールを開始するときに機能します。

編集2:

This is how it should look!

ありがとう:は、これはのようになります方法です!

self.cellBackgroundView.layer.shadowPath = UIBezierPath(rect: self.cellBackgroundView.bounds).cgPath 

トリックを行う必要があります。

+0

「常にオフで、中央にない」とは何ですか? – Koen

+0

@Koen私が付けたイメージで見ることができます。影はセルのすぐ下にあるはずです。どのように見えるべきかの写真を投稿します。 – kuklis

答えて

2

あなたはせずにラインをを掲載コードを試してみてください。

+0

これは甘いです!作品! – RaffAl

関連する問題