I'm trying to figure out how to mask a UIView to display a shape that represents a Square with half of a circle sitting ontop of it.
Basically, it would be like applying a border radius to only the top two corners to round them out and create an arc.
I'm using swift, and this is driving me crazy.
EDIT: CornerRadius does not do what I want. I feel like I'll have to use a CGShapeLayer but I'm not sure how to create the arc.
EDIT3:
Considering explaining what I want, providing pictures, and explaining that I didn't understand what I needed to do, or how I needed to do it isn't enough for some people, here's what I've tried:
Attempted setting the layer.cornerRadius
property, while pushing the bottom of the view out past the screen to hide the bottom corners from appearing cut off, this type of masking was too circular and did not provide the proper arc results.
I've attempted using UIBezierPath
setting the top two corners to use a cornerRadii of the views width / 2
. This also did not yield proper results. Upon attempting to hardcode values into the cornerRadii, I noticed that regardless of the value, I could not seem to obtain the results that I had wanted.
What other options are there? Or am I just using the BezierPath incorrectly?
EDIT 4:
Here is my original code.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let bezierPath = UIBezierPath(roundedRect: navBarView.bounds, byRoundingCorners: [.TopLeft, .TopRight], cornerRadii: CGSizeMake(navBarView.bounds.width / 2, navBarView.bounds.width / 2)).CGPath;
let shapeLayer = CAShapeLayer();
shapeLayer.bounds = navBarView.bounds
shapeLayer.path = bezierPath
navBarView.layer.mask = shapeLayer
updateUI() // <-- Label text, etc.
}
Also, as stated before, had attempted doing navBarView.layer.cornerRadius = x
UIImage
. – ConawayviewDidLayoutSubviews()
– Hobbism