Reputation: 649
I want to create a semi-circle arch. I have achieved that using UIBezierPath. However, my issue is that the location of my arch is not where I want it to be.
As you can see from the image above, I want the blue object to be centred, but it is leaning to the left. Code below.
@IBOutlet weak var logo_backdrop: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
//Setting Login View Background
let bgColor = UIColor(red: 128, green: 206, blue: 201)
self.view.backgroundColor = bgColor
//Setting Logo Backdrop color
let backdrop = UIColor(red:183, green:227, blue:239)
logo_backdrop.backgroundColor = backdrop
//Setting Round Corner for Logo Backdrop
let maskPath = UIBezierPath(roundedRect: logo_backdrop.bounds,
byRoundingCorners: [.bottomLeft, .bottomRight],
cornerRadii: CGSize(width: 100.0, height: 100.0))
maskPath.move(to: CGPoint(x: view.frame.width, y: 0.0))
let shape = CAShapeLayer()
shape.frame = logo_backdrop.bounds
shape.path = maskPath.cgPath
logo_backdrop.layer.mask = shape
}
Upvotes: 0
Views: 157
Reputation: 535526
One obvious problem is that your code is in viewDidLoad
. That is too soon, as the various views have not yet taken on their real size. But your code depends upon that size, so it must not be run too early.
For example, your bezier path depends upon logo_backdrop.bounds
, but those bounds are exactly what we do not know in viewDidLoad
.
Upvotes: 1