Rounded corner UITextField Xcode
5 answers
Just follow these steps
STEP 1: Importing the QuartzCore structure into your class:
#import <QuartzCore/QuartzCore.h>
STEP 2: apply encoding
textField.layer.cornerRadius=6.0f;
textField.layer.masksToBounds=YES;
textField.layer.borderColor=[[UIColor blueColor]CGColor];
textField.layer.borderWidth= 1.0f;
or
[textField.layer setBorderColor:[[UIColor blueColor] CGColor]];
[textField.layer setBorderWidth:2.o];
[textField.layer setCornerRadius:5.0];
+1
source to share
You can use:
(UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii
Example:
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:textField.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
textField.layer.mask = maskLayer;
0
source to share
I think you should write a CALayer extension. Swift 3.x - 4.x
extension CALayer {
func addRadius(_ corners: UIRectCorner, radius: CGFloat, view: UIView) {
let mask = CAShapeLayer()
mask.bounds = view.frame
mask.position = view.center
mask.path = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)).cgPath
view.layer.mask = mask
}
func addRadius(radius: CGFloat) {
self.cornerRadius = radius
}
}
Using
class ViewController: UIViewController {
@IBOutlet var messageTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
messageTextField.layer.addRadius(radius: 8.0)
}
}
I hope for your help :)
0
source to share