我试图用layer.cornerRadius来获得圆角,以进行分段控制,但是它实际上对我不起作用,我想根据框架来获取cornerRadius
这是我的代码
func setupView(){
layer.masksToBounds = true
// here my corner radius
layer.cornerRadius = frame.height / 2.0
layer.borderColor = UIColor.walkthroughOrangeAccent.cgColor
layer.borderWidth = 2
backgroundColor = UIColor.clear
setupImageView()
addIndividualItemConstraints(items: imageViewList, mainView: self, padding: 0)
insertSubview(thumbView, at: 0)
}
答案 0 :(得分:0)
我怀疑由于布局限制,您没有看到拐角半径。尝试对分段控件进行子类化,并在layoutSubviews
中设置拐角半径:
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = frame.height / 2.0
}
或者,如果您在视图控制器中:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
segmentedControl.layer.cornerRadius = segmentedControl.frame.width / 2.0
}