I wrote a simple blog post explaining this.įunc roundCorners(radius: CGFloat = 10, corners: UIRectCorner =. Pay attention to the fact that if you have layout constraints attached to it, you must refresh this as follows in your UIView subclass: override func layoutSubviews() // Specify which corners to round let corners UIRectCorner(arrayLiteral: UIRectCorner.topLeft, UIRectCorner.topRight, UIRectCorner.bottomLeft, UIRectCorner. what if i want only 2 rounded corner (top left and top right ) with border on. The spec says The UA may reduce or treat as zero the border-radius for a given corner. Swift 3 Extension for adding border to one side of UIView - UIView+Border.swift. Swift 3.0 version: let path = UIBezierPath(roundedRect:viewToRound.bounds,īyRoundingCorners:,ĬornerRadii: CGSize(width: 20, height: 20)) The values before the slash set the horizontal semi-axes, and the. Swift version with some improvements: let path = UIBezierPath(roundedRect:viewToRound.bounds, byRoundingCorners:, cornerRadii: CGSizeMake(20, 20)) self is a custom UITableViewCell: UIBezierPath *maskPath = [UIBezierPathīezierPathWithRoundedRect:īyRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)ĬAShapeLayer *maskLayer = In my code below I was rounding the bottom corners of the _backgroundView with a radius of 3 pixels. Create a bezier mask and apply it to your view. I am not sure why your solution did not work but the following code is working for me.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |