4

我从 Interface Builder(IB) 创建了一个 UITextField。因为我想要自定义样式,所以我在 IB 中选择了 None 样式。在 viewDidLoad 上,我为它分配了以下样式:

txtEmail.layer.cornerRadius = 8.0;
txtEmail.layer.borderColor = [UIColor colorWithWhite:199.0/255.0 alpha:1].CGColor;
txtEmail.layer.borderWidth = 1.0;
txtEmail.layer.shadowColor = [UIColor blackColor].CGColor;
txtEmail.layer.shadowOpacity = 0.17;
txtEmail.layer.shadowOffset = CGSizeMake(-0.9,0.9);
txtEmail.layer.shadowRadius = 1.1;

// This is to provide a left padding for None styled textfields
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
txtEmail.leftView = paddingView;
txtEmail.leftViewMode = UITextFieldViewModeAlways;

现在我的文本字段的样式变得完美,但我的占位符文本(在 IB 中提供)也继承了该阴影。我怎样才能摆脱它?

4

1 回答 1

0

找到下面的代码它工作正常,你需要删除shadowRadius

txtEmail.backgroundColor = [UIColor clearColor];
txtEmail.layer.cornerRadius = 8.0;
txtEmail.layer.borderColor = [UIColor colorWithWhite:199.0/255.0 alpha:1].CGColor;
txtEmail.layer.borderWidth = 1.0;
txtEmail.layer.shadowColor = [UIColor blackColor].CGColor;
txtEmail.layer.shadowOpacity = 0.17;
txtEmail.layer.shadowOffset = CGSizeMake(-0.9,0.9);
txtEmail.layer.masksToBounds = false;

// This is to provide a left padding for None styled textfields
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
txtEmail.leftView = paddingView;
txtEmail.leftViewMode = UITextFieldViewModeAlways;
[self.view addSubview:txtEmail];

图片

于 2017-10-11T08:55:27.970 回答