问题描述
- UITextField遇到问题
-
创建了UITextField,具体代码:UItextField *mobileNumberField = [[UITextField alloc] initWithFrame:CGRectMake(10, 195, 300, 41)]; mobileNumberField.delegate = self; mobileNumberField.borderStyle = UITextBorderStyleRoundedRect; [mobileNumberField.layer setCornerRadius:14.0f]; mobileNumberField.placeholder = @"Mobile Number"; [self.paymentsHomeView addSubview:mobileNumberField];
但是显示的效果是这样:
不知道为什么框会断开。请高手帮忙改成这样的效果:
解决方案
很简单,删除这行:
mobileNumberField.borderStyle = UITextBorderStyleRoundedRect;
然后再加上这些:
[mobileNumberField setBackgroundColor:[UIColor whiteColor]];
[mobileNumberField.layer setBorderColor:[UIColor grayColor].CGColor];
[mobileNumberField.layer setBorderWidth:1.0];
解决方案二:
相信这个代码能帮你
UITextField *mobileNumberField = [[UITextField alloc] initWithFrame:CGRectMake(10, 195, 300, 41)];
mobileNumberField.delegate = self;
mobileNumberField.layer.borderWidth = 1.0f;
mobileNumberField.layer.borderColor = [UIColor lightGrayColor].CGColor;
mobileNumberField.
// mobileNumberField.borderStyle = UITextBorderStyleRoundedRect;
[mobileNumberField.layer setCornerRadius:14.0f];
mobileNumberField.placeholder = @"Mobile Number";
[self.paymentsHomeView addSubview:mobileNumberField];
时间: 2024-09-04 18:24:12