我必须像上图那样自定义 UITextField,所以我尝试编写自定义类扩展 UITextField 类。但我的问题是:矩形的描边阴影轮廓,并在我的自定义代码中为文本字段设置白色背景是:
- (void)drawRect:(CGRect)rect
{
// Drawing code
self.autocorrectionType = UITextAutocorrectionTypeNo;
self.autocapitalizationType = UITextAutocapitalizationTypeNone;
CALayer *layer = self.layer;
layer.cornerRadius = 15.0;
layer.masksToBounds = YES;
layer.borderWidth = 1.0;
layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor];
[layer setShadowColor: [[UIColor blackColor] CGColor]];
[layer setShadowOpacity:1];
[layer setShadowOffset: CGSizeMake(2.0, 2.0)];
[self setClipsToBounds:NO];
[self setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
}
- (CGRect)textRectForBounds:(CGRect)bounds {
return CGRectMake(bounds.origin.x + 20, bounds.origin.y + 8,
bounds.size.width - 40, bounds.size.height - 16);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [self textRectForBounds:bounds];
}
所以我的问题是:我缺少什么代码(这里设置了白色背景,为边框设置了轮廓阴影)感谢您的帮助!