Подтвердить что ты не робот

Как установить стиль границы UITextfield

Как я могу настроить стиль рамки UITextField программно?

Я создаю свое текстовое поле следующим образом:

UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(65, 200, 200, 30)];
tfText.backgroundColor = [UIColor colorWithRed:0.2 green:0.9 blue:0.5 alpha:0.3];       
tfText.textAlignment = UITextAlignmentCenter;
[self.view addSubview:tfText];
[tfText release];
4b9b3361

Ответ 1

Попробуйте это

UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(65, 200, 200, 30)];
tfText.backgroundColor = [UIColor colorWithRed:0.2 green:0.9 blue:0.5 alpha:0.3];       
tfText.textAlignment = UITextAlignmentCenter;
// Border Style None
[tfText setBorderStyle:UITextBorderStyleNone];
[self.view addSubview:tfText];
[tfText release];

Для справки

Ответ 2

Вы можете использовать Quartzcore и свойства слоя.

sometextfield.layer.borderWidth = 1;
sometextfield.layer.borderColor = [[UIColor redColor] CGColor];

Не забудьте добавить QuartzCore в ваш проект и импортировать его там, где вы хотите его использовать.

Ответ 3

Ниже, каждый может быть использован программно,

[textField setBorderStyle:UITextBorderStyleNone];

[textField setBorderStyle:UITextBorderStyleLine];

[textField setBorderStyle:UITextBorderStyleBezel];

[textField setBorderStyle:UITextBorderStyleRoundedRect];

где textField - это выход из UITextField

Ответ 4

Я знаю, вопрос об Obj-C, но я пришел сюда для Свифта. И в Swift это делается так:

txt.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0);
txt.borderStyle = UITextBorderStyle.RoundedRect
let myColor : UIColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0);
txt.layer.borderWidth = 3;
txt.layer.borderColor = myColor.CGColor;

Это устанавливает пользовательский цвет фона и границу в одном цвете (чтобы скрыть границу, но все еще имеет некоторое отступы между текстом и границами текстового поля.

Ответ 5

[pTxtTithiTime.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];

[pTxtTithiTime.layer setBorderWidth:0.8];

//Округленная угловая часть, где вы указываете свой угловой угол обзора:

  pTxtTithiTime.layer.cornerRadius = 5;

  pTxtTithiTime.clipsToBounds = YES;

Ответ 6

Вы можете сделать UITextField программно следующим образом:

UITextField *txtField = [[UITextField alloc]initWithFrame:CGRectMake(10, 260, 280, 30)]; // your required coordinate
txtField.delegate =        self;
txtField.placeholder =     @"My TextField";
txtField.borderStyle =      UITextBorderStyleNone;
txtField.keyboardType =        UIKeyboardTypeDefault;
txtField.backgroundColor =       [self setBackGroundColorOnButton];
txtField.layer.cornerRadius = 5.0;