First of all, let’s add an UIImageView Object in our storyboard. To change only one corner or give a different corner radius value to each of them, click the chain in the middle and fill the corner radius field for each corner. Every UI element in iOS is based on a layer. What we want to do is instead overwrite its image so we have control on the color, corner radius, etc. Overall, this has the desired effect of rounding the corners on the UIView and displaying a shadow. Swift version with some improvements: let path = UIBezierPath(roundedRect:viewToRound.bounds, byRoundingCorners:, cornerRadii: CGSizeMake(20, 20)) To make an image with round corners or to make any view or button or any UI element with round corners in swift, we need to access the corner radius property of its layer. This sets the desired corner radius on any sublayer in the current layer hierarchy. self is a custom UITableViewCell: UIBezierPath *maskPath = [UIBezierPathīezierPathWithRoundedRect:īyRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)ĬAShapeLayer *maskLayer =
#Corner radius for one corner ios code#
In my code below I was rounding the bottom corners of the _backgroundView with a radius of 3 pixels. In reality, the window still had the straight border with square corners but since the window itself was clear, you couldn't see the border. As a result, the app window appeared to have a ragged, burned edge. Create a bezier mask and apply it to your view. The image had a ragged edge that look like a piece of paper that had gone through a fire with its borders burned. I am not sure why your solution did not work but the following code is working for me.