作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 UITextField
,我在 rightView
中添加了一个图像。我已经向这个 rightView
添加了一个手势,我想让它在 UITextField
被禁用时工作,因为这个 View 只在不编辑时显示。
下面是用于将外观应用到 UITextField
并将图像应用到 rightView 的代码:
- (void)applyAppearanceToTextField:(UITextField *)textField withRoundingCorner:(UIRectCorner)corner withIcon:(NSString *)icon {
CAShapeLayer *shape = [[CAShapeLayer alloc] initWithLayer:textField.layer.mask];
UIBezierPath *shadow = [UIBezierPath bezierPathWithRoundedRect:textField.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(5, 5)];
shape.path = shadow.CGPath;
textField.layer.mask = shape;
// Apply space to the left as a padding
[textField setLeftView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, textField.bounds.size.height)]];
[textField setLeftViewMode:UITextFieldViewModeAlways];
// Add the icon image to the right view
CGFloat height = textField.bounds.size.height;
UIImage *image = [UIImage imageWithIcon:icon backgroundColor:[UIColor clearColor] iconColor:[UIColor grayColor] andSize:CGSizeMake(height / 2, height / 2)];
image = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUpMirrored];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setBounds:CGRectMake(5, 0, image.size.width, image.size.width)];
[imageView setUserInteractionEnabled:YES];
[textField setRightView:imageView];
[textField setRightViewMode:UITextFieldViewModeUnlessEditing];
[textField.rightView setExclusiveTouch:YES];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleIconTap:)];
[textField.rightView addGestureRecognizer:tapGesture];
}
- (void)handleIconTap:(UITapGestureRecognizer *)gesture {
NSLog(@"handleIconTap");
}
在 viewDidLoad
中,我检查该字段是否已填充,因此该字段已被禁用。当 UITextField
被禁用时,如何在 leftView/rightView 中启用点击?
最佳答案
关于ios - 禁用 UITextField 时如何在 leftView/rightView 中启用点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35701355/
我是一名优秀的程序员,十分优秀!