カスタムtableViewのセルで、上に丸みを帯びたコーナーを持つUIViewを作成したいと思います。丸みを帯びたコーナーがUIViewのサイズを変更する
self.layoutIfNeeded()
let rectShape = CAShapeLayer()
rectShape.bounds = headerView.layer.frame
rectShape.position = headerView.center
rectShape.path = UIBezierPath(roundedRect: headerView.layer.bounds, byRoundingCorners: [ .topLeft, .topRight], cornerRadii: CGSize(width: 10, height: 10)).cgPath
headerView.layer.backgroundColor = UIColor.green.cgColor
headerView.layer.mask = rectShape
問題はときということである:ここで私は以下の私が行っているビューの丸みを帯びた角を設定するには、この部分の
headerView.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 8).isActive = true
headerView.topAnchor.constraint(equalTo: self.topAnchor, constant: 4).isActive = true
headerView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -8).isActive = true
headerView.heightAnchor.constraint(equalToConstant: 40).isActive = true
ベローのUIViewの制約を設定していたコードの一部ですこのコードブロックは、ビューのサイズが変更された丸いコーナーを設定するために使用されます。ここでは、出力コードのこの部分のない
、結果は以下の通りですさ:ビューのサイズが変更された理由を
私の質問はありますか?私は間違っているの?
私は確信していませんが、これは、おそらく、レイアウトの「レイヤー」を変更しているため、自動レイアウトの制約に影響していると思われます。あなたがしたいのはビューの角を丸くしているだけなので、 'CAShapeLayer'を使う必要はありません。 –
丸みを帯びた角を上にしたいのですが、それは私がCAShapeLayerを使っている理由です。 –