我尝试了以下方法,但只在圆圈周围创建了一个边框,而不是一个单独的矩形边框。 如此处所示
cell.layer.borderWidth = 1.0
cell.layer.borderColor = UIColor.black.cgColor
我尝试了以下方法,但只在圆圈周围创建了一个边框,而不是一个单独的矩形边框。 如此处所示
cell.layer.borderWidth = 1.0
cell.layer.borderColor = UIColor.black.cgColor
我不确定它是否适合您,但您可以尝试添加这样的附加层:
var rect = UIView()
var circle: CALayer?
override func loadView() {
// create view with border
rect.frame = CGRect(x: 50, y: 50, width: 300, height: 200)
rect.layer.borderColor = UIColor.black.cgColor
rect.layer.backgroundColor = UIColor.clear.cgColor
rect.layer.borderWidth = 2
// add circle layer
let circle = CALayer()
circle = UIColor.red.cgColor
// add circle layer on view with drawn border
rect.layer.addSublayer(circle)
view.addSubview(rect)
circle = circle
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// layout circle on your view
let radius = min(rect.frame.width, rect.frame.height) * 0.5
circle?.frame = CGRect(x: rect.bounds.width / 2 - radius / 2, y: rect.bounds.height / 2 - radius / 2, width: radius, height: radius)
circle?.cornerRadius = radius / 2
}
但可能这不是最好的选择,也许有人给你更好的解决方案。
如果它不适合你,请提供更多关于你的问题的细节。
代替
cell.layer.borderWidth = 1.0
cell.layer.cornerRadius = 10
cell.layer.borderColor = UIColor.black.cgColor
你有没有尝试过?
cell.layer.borderWidth = 1.0
cell.layer.borderColor = UIColor.black.cgColor