2016-06-23 4 views
0
UITextField *tf3 = [[UITextField alloc] initWithFrame:CGRectMake(10, tf2.frame.origin.y+55,100, 30)]; 
tf3.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0]; 
//tf.font = [UIFont fontWithName:@"Helvetica-Bold" size:25]; 
tf3.backgroundColor=[UIColor whiteColor]; 
tf3.borderStyle=UITextBorderStyleLine; 
[email protected]"Save"; 
tf3.textAlignment=UITextAlignmentCenter; 
view1 = [[UIView alloc] initWithFrame:CGRectMake(0,270, 100, 40)]; 
[view1 addSubview:tf3]; 

Как добавить кнопку сохранения к этому textField без использования раскадровки.Как добавить кнопку в текстовое поле в поле зрения

ответ

0

использовать этот код,

 UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     button.frame = CGRectMake(65, 0, 35, 30); 
     button.backgroundColor = [UIColor blueColor]; 
     [button setTitle:@"Save" forState:UIControlStateNormal]; 
     [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; 
     [tf3 addSubview:button]; 

надеюсь, его полезной

0

Вы можете добавить что-то вроде

UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; 
[tf3 addSubview:btn] 
0

Правильный путь:

В UITextField вас иметь два свойства/вид слева и правый вид/посмотреть, как их включить.

я думаю, что это что-то вроде:

tf3.leftViewMode = .AlwaysEnabled // Here you can place a enum options, such as always visible, visible only while edit and stuff 

Следующий шаг: Создать UIButton:

var saveButton = UIButton(frame: CGRect(x: 0, y: 0:, width: 30, height: 30) 
saveButton.setImage(named: "your_imgae", state: .Normal) 
saveButton.addTarget(self, action: #selector(saveButtonPressed(_:) ...) 
tf3.leftView = saveButton 

Следующий шаг Создайте функцию saveButtonPressed(sender: UIButton) и слушать там клик мероприятие.

Я не тестировал его, но думаю, он должен работать.