当我在文本框内单击时,如何将正按钮添加到UITextField,如下面的屏幕所示?点击此按钮后,它将启动iPhone联系人应用程序。我非常感谢任何代码示例。由于将按钮添加到uitextfield
15
A
回答
8
使用以下方法添加UIButton
[self.txtField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- (BOOL) textFieldDidChange:(UITextField *)textField
{
UIButton *btnColor = [UIButton buttonWithType:UIButtonTypeCustom];
[btnColor addTarget:self action:@selector(btnColorPressed:) forControlEvents:UIControlEventTouchUpInside];
btnColor.frame = CGRectMake(self.txtTag.bounds.size.width - 50, 5, 25, 25);
[btnColor setBackgroundImage:[UIImage imageNamed:@"PaintPickerButton.png"] forState:UIControlStateNormal];
[self.txtTag addSubview:btnColor];
return YES;
}
或写
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3f];
// self.scrollView.frame = CGRectMake(0, 35, self.view.bounds.size.width, self.view.bounds.size.height - 250);
[UIView commitAnimations];
UIButton *btnColor = [UIButton buttonWithType:UIButtonTypeCustom];
[btnColor addTarget:self action:@selector(btnColorPressed:) forControlEvents:UIControlEventTouchUpInside];
btnColor.frame = CGRectMake(150, 5, 25, 25);
[btnColor setBackgroundImage:[UIImage imageNamed:@"PaintPickerButton.png"] forState:UIControlStateNormal];
[self.txtField addSubview:btnColor];
return YES;
}
8
下面的代码使用中的UITextField添加按钮。
-(void)ViewDidLoad{
UITextField *txt = [[UITextField alloc]initWithFrame:CGRectMake(140, 120, 160, 40)];
txt.returnKeyType = UIReturnKeyDone;
txt.placeholder = @"Enter or Mobile Number";
[txt setBorderStyle:UITextBorderStyleRoundedRect];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"crossImg.png"] forState:UIControlStateNormal];
button.imageEdgeInsets = UIEdgeInsetsMake(0, -16, 0, 0);
[button addTarget:self action:@selector(clearText:) forControlEvents:UIControlEventTouchUpInside];
txt.rightView = button;
txt.rightViewMode = UITextFieldViewModeAlways;
[self.view addSubview:txt];
}
-(IBAction)clearText:(id)sender{
}
3
使用UITextField
rightView
财产。 在textFieldDidBeginEditing:
代表创建按钮与您想要的动作&设置为rightView
。 并在textFieldDidEndEditing:
设置为零rightView
1
你也可以去自定义视图蚂蚁然后添加到它的子视图。然后你隐藏它。
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == yourFirstTextField)
{
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setImage:[UIImage imageNamed:@"addImage.png"] forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(yourActionHere) forControlEvents:UIControlEventTouchUpInside];
textField.rightViewMode = UITextFieldViewModeWhileEditing;
textField.rightView = addButton;
}
}
你可以,如果你在IB添加字段使用上面的方法:只有当用户点击它
9
您可以使用下面的代码这一点,将是可见的。
如果通过代码创建它,你需要添加下面的代码创建时:
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setImage:[UIImage imageNamed:@"addImage.png"] forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(yourActionHere) forControlEvents:UIControlEventTouchUpInside];
textField.rightViewMode = UITextFieldViewModeWhileEditing;
textField.rightView = addButton;
0
self.locationName.clearButtonMode = UITextFieldViewModeWhileEditing;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 30, 30);
[button setImage:[UIImage imageNamed:@"goButtonIcon.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(goButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.locationName.rightView = button;
self.locationName.rightViewMode = UITextFieldViewModeUnlessEditing;
,然后调用这个方法:
-(IBAction)goButtonClicked:(id)sender{
}
self.locationName ------->的UITextField引用(在viewDidLoad中你可以这样写代码)
相关问题
- 1. 将“清除”按钮添加到iPhone UITextField
- 2. 在UITextField中添加按钮
- 3. 按钮点击添加UItextfield
- 4. 通过单击按钮将对象从UITextField添加到NSMutableArray
- 5. 有一个按钮将文本快速添加到UITextField中
- 6. 如何添加清除按钮UITextfield?
- 7. 将按钮添加到jtable
- 8. 将按钮添加到UITableView
- 9. 将按钮添加到jtable
- 10. 将按钮添加到MKPointAnnotation
- 11. 将按钮添加到JPanel
- 12. 将按钮添加到UILabel
- 13. 将按钮添加到QTableview
- 14. 将按钮添加到UIDatePicker
- 15. 将OnGestureListener添加到按钮?
- 16. 将按钮添加到ListActivity
- 17. 将按钮添加到UIScrollview
- 18. 将按钮添加到infoWindow
- 19. 将按钮添加到BrowseFragment
- 20. 将UIGesture添加到按钮
- 21. 将ActionListener添加到按钮
- 22. 将按钮添加到JScrollpane
- 23. 将按钮添加到gridview
- 24. 将按钮添加到ViewPager
- 25. 将按钮添加到ListActivity
- 26. 将按钮添加到JDesktopPane
- 27. 将MD5添加到UITextField
- 28. 添加一个UITextField到一个按钮上的UITableView点击
- 29. 在'完成'按钮上添加验证方法添加到UITextField输入法
- 30. 值添加到UITextField
为什么向下票呢? –