我有一个UITextField
添加到视图中,我正在尝试更改它的默认外观。
我想要的是改变角半径,但只在顶部/底部。我这样做是这样做的:
UIBezierPath *usernameMaskPathWithRadiusTop = [UIBezierPath bezierPathWithRoundedRect:username.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(4.0, 4.0)];
UIBezierPath *passwordMaskPathWithRadiusBottom = [UIBezierPath bezierPathWithRoundedRect:password.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(4.0, 4.0)];
CAShapeLayer *usernameMaskLayer = [[CAShapeLayer alloc] init];
usernameMaskLayer.frame = username.bounds;
usernameMaskLayer.path = usernameMaskPathWithRadiusTop.CGPath;
CAShapeLayer *passwordMaskLayer = [[CAShapeLayer alloc] init];
passwordMaskLayer.frame = password.bounds;
passwordMaskLayer.path = passwordMaskPathWithRadiusBottom.CGPath;
[username setTextAlignment:NSTextAlignmentLeft];
[username setClearButtonMode:UITextFieldViewModeWhileEditing];
usernameLayer.shadowOpacity = 0.0;
[usernameLayer setMask:usernameMaskLayer];
[password setTextAlignment:NSTextAlignmentLeft];
[username setClearButtonMode:UITextFieldViewModeWhileEditing];
passwordLayer.shadowOpacity = 0.0;
[passwordLayer setMask:passwordMaskLayer];
哪里UITextField *username
和和UITextField *password
_CAShapeLayer *usernameLayer = username.layer
CAShapeLayer *passwordLayer = password.layer
如前所述。
问题是,在我执行上述操作后,我根本没有得到任何字段,实际上它们在那里,但一切都是透明的,文本和背景颜色。我不确定如何找回它或如何解决我做错的任何事情。
我到底该怎么做我正在尝试的事情?