我在点击按钮上使用rightmodeview将图像设置为textFiled, 现在我想要的是,我想在不触摸按钮的情况下在点击textField时隐藏图像? 帮帮我
答案 0 :(得分:0)
这段代码对我有用
-(void)textFieldDidBeginEditing:(UITextField *)textField {
//set right view nil
}
并确保为文本字段设置UITextField的委托
在viewDidLoad
中添加以下代码yourTextField.delegate = self;
答案 1 :(得分:0)
做类似的事情:
-(void)textFieldDidBeginEditing:(UITextField *)textField {
textfield.rightView=nil;
//Do other stuff,if you want to do
}
答案 2 :(得分:0)
我创建了一个示例,我尝试了它正常工作。
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *txtFldImage;
@end
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
txtFldImage.rightViewMode = UITextFieldViewModeAlways;
txtFldImage.rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"boss-icon.png"]];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
txtFldImage.rightView = nil;
}
运行应用时
当我进入或触摸textField
时