當我在文本框內單擊時,如何將正按鈕添加到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
爲什麼向下票呢? –