【发布时间】:2017-10-04 04:32:17
【问题描述】:
我正在尝试创建一个中间有一个孔的圆形 UIView,然后将该视图与另一个视图的顶部相结合。但是我不确定我是否以正确的方式进行操作
到目前为止,这就是我在操场上的做法:
import Foundation
import UIKit
import CoreGraphics
extension UIColor {
static func getRandomColor() -> UIColor {
//Generate between 0 to 1
let red:CGFloat = CGFloat(drand48())
let green:CGFloat = CGFloat(drand48())
let blue:CGFloat = CGFloat(drand48())
return UIColor(red:red, green: green, blue: blue, alpha: 1.0)
}
}
func makeCircularView(x: Int = 0 , y : Int = 0 , width: Double, height : Int, color: UIColor) -> UIView {
let view : UIView = UIView(frame:CGRect(x: x, y: y, width: Int(width), height: height))
view.alpha = 0.5
view.layer.cornerRadius = view.bounds.size.width / 2
view.backgroundColor = color
view.layer.masksToBounds = true
return view
}
let uiView = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
uiView.backgroundColor = .red
uiView.clipsToBounds = true
uiView.layer.shadowRadius
uiView.layer.cornerRadius = 5
uiView
let cir : UIView
let circle2 : UIView
cir = makeCircularView(width : 30 , height : 30, color: UIColor.gray)
circle2 = makeCircularView( x: Int(7.5) , y : Int(7.5), width: 15, height: 15, color: UIColor.clear)
cir.addSubview(circle2)
uiView.addSubview(cir)
cir.topAnchor.constraint(equalTo: uiView.topAnchor, constant: -20).isActive = true
cir.leadingAnchor.constraint(equalTo: uiView.leadingAnchor, constant: -10).isActive = true
【问题讨论】:
-
你找到解决方案了吗?
-
还没有,我今晚试试,然后我会更新你...
-
我刚刚做了这件事
-
@HimanshuMoradiya 你能贴出你的代码吗?
-
我刚刚制作了一个 .xib 文件并创建了包含您的 2 视图的文件文件
标签: ios swift uiview uibezierpath