iphone – 添加按钮到uitextfield
发布时间:2020-12-15 01:39:53 所属栏目:百科 来源:网络整理
导读:当我点击里面的文本框,如何添加加号按钮到UITextField,如下面的屏幕所示?当此按钮被点击时,它将启动iPhone联系人应用程序.我非常感谢任何代码示例.谢谢 解决方法 使用以下方法添加UIButton [self.txtField addTarget:self action:@selector(textFieldDidCha
当我点击里面的文本框,如何添加加号按钮到UITextField,如下面的屏幕所示?当此按钮被点击时,它将启动iPhone联系人应用程序.我非常感谢任何代码示例.谢谢
解决方法
使用以下方法添加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,25); [btnColor setBackgroundImage:[UIImage imageNamed:@"PaintPickerButton.png"] forState:UIControlStateNormal]; [self.txtField addSubview:btnColor]; return YES; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |