我将uiview添加到项目的stackview中。但是它不能正常工作。我想要一个stackview里面有一个视图。并且它具有拐角半径,拐角半径无法正确显示并覆盖。
tag_stack.spacing = 30
tag_stack.translatesAutoresizingMaskIntoConstraints = false
tag_stack.axis = .horizontal
stack_scroll.addSubview(tag_stack)
for views in selected{
let holder_view = UILabel()
let container = UIView()
container.translatesAutoresizingMaskIntoConstraints = false
holder_view.translatesAutoresizingMaskIntoConstraints = false
container.heightAnchor.constraint(equalToConstant: 25).isActive = true
container.backgroundColor = UIColor(red: 47/255, green: 175/255, blue: 249/255, alpha: 1.0)
container.layer.cornerRadius = 12.5
container.addSubview(holder_view)
holder_view.font = UIFont.systemFont(ofSize: 12)
holder_view.textColor = .white
holder_view.centerYAnchor.constraint(equalTo: container.centerYAnchor, constant: 0).isActive = true
holder_view.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 5).isActive = true
holder_view.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -5).isActive = true
holder_view.text = views
tag_stack.addArrangedSubview(container)
}
tag_stack.leadingAnchor.constraint(equalTo: stack_scroll.leadingAnchor).isActive = true
tag_stack.trailingAnchor.constraint(equalTo: stack_scroll.trailingAnchor).isActive = true````
答案 0 :(得分:0)
您似乎忘记了设置必需的属性。不要忘记为所需的视图添加view.clipsToBounds = false
和view.layer.cornerRadius = x
。
答案 1 :(得分:0)
您忘记添加所需的属性,只是转到属性,然后查看属性并检查clipsToBound(如果您绑定了控件),或者可以通过添加一行代码来解决此问题,只需添加
if (view.clipsToBound == true){
view.clipsToBound = false
}