答案 0 :(得分:15)
您可以使用此代码。这对我很有用:
UITextField* txtfield = [[UITextField alloc]initWithFrame:CGRectMake(10, 50, 300, 32)];
[txtfield setBorderStyle:UITextBorderStyleNone];
txtfield.layer.cornerRadius = 15.0;
txtfield.layer.borderWidth = 2.0;
txtfield.layer.borderColor = [UIColor redColor].CGColor;
txtfield.layer.masksToBounds = YES;
[self.view addSubview:txtfield];
在视图中设置背景,并将 borderColor设置为clearColor 。