ios - 创建具有重叠圆的 View

标签 ios swift

我正在尝试创建一个简单的 UIView 线,然后在顶部创建一个圆圈。然而,我不确定如何在不产生层次结构问题的情况下绘制圆圈?到目前为止,我有下面的内容,它只是创建了该行

线

    self.stepLine = UIView()
    self.stepLine.translatesAutoresizingMaskIntoConstraints = false
    stepView.addSubview(self.stepLine)

    self.stepLine.backgroundColor = Color.theme.value

    self.stepLine.bottomAnchor.constraint(equalTo: stepView.bottomAnchor, constant: -4).isActive = true
    self.stepLine.heightAnchor.constraint(equalToConstant: 6).isActive = true
    self.stepLine.leftAnchor.constraint(equalTo: stepView.leftAnchor).isActive = true



override func layoutSubviews() {
    self.stepLine.widthAnchor.constraint(equalToConstant: self.frame.width/2).isActive = true
}

插图

enter image description here

最佳答案

let circleView = UIView()
circleView.layer.cornerRadius = 10 // half of the width/height dimension
circleView.translatesAutoresizingMaskIntoConstraints = false
stepView.addSubview(circleView)

circleView.centerYAnchor.constraint(equalTo: stepLine.centerYAnchor).isActive = true
circleView.trailingAnchor.constraint(equalTo: stepLine.trailingAnchor).isActive = true
circleView.widthAnchor.constraint(equalToConstant: 20).isActive = true
circleView.heightAnchor.constraint(equalToConstant: 20).isActive = true

或者其一些变体。但考虑到您所提供的代码的性质,这是我建议的一般概念。

关于ios - 创建具有重叠圆的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802919/

相关文章:

ios - UIGestureRecognizer 阻止 TableView 编辑

swift - 只画半个圆

ios - Swift 编译器在handleDeferredImports 中出现段错误

ios - 如何在 "Confirm to Delete"状态且表格处于编辑模式时自定义 UITableView 单元格

ios - 如何在 Xcode 中创建具有多列的 UI TableView?

ios - 您可以使用与开发者帐户不同的帐户提交到应用商店吗

ios - 按值将对象数组映射到新的数组数组中

ios - 如何修复 pod 安装错误 glog 太旧或缺少 Windows 10 中的 native ios

ios - WKWebview运行JavaScript

ios - swift 2 : Sound on NSTimer Always Plays Twice