UITextField添加点击高亮状态
来源:互联网 发布:王进喜照片泄密知乎 编辑:程序博客网 时间:2024/05/24 07:26
一、继承自UITextfield自定义一个SSTouchTextField
代码如下:
#import "SSTouchTextField.h"@implementation SSTouchTextField#pragma mark - Private- (void)setBackgroundHighlighted:(BOOL)highlighted{ [UIView animateWithDuration:0.3f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{ if (highlighted) { [self setBackgroundColor:SS_LINE_COLOR]; } else { [self setBackgroundColor:[UIColor clearColor]]; } } completion:^(BOOL finished) { }];}#pragma mark - Overwrite- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ [super touchesBegan:touches withEvent:event]; [self setBackgroundHighlighted:YES];}- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ [super touchesMoved:touches withEvent:event];}- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ [super touchesEnded:touches withEvent:event]; [self setBackgroundHighlighted:NO];}- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{ [super touchesCancelled:touches withEvent:event]; [self setBackgroundHighlighted:NO];}// 增大点击区域- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ CGPoint convertPoint = [self convertPoint:point toView:self.superview]; UIEdgeInsets edgeInset = UIEdgeInsetsMake(0, 100, 0, 100); CGRect edgeFrame = CGRectMake(self.view_minX - edgeInset.left, self.view_minY - edgeInset.top, self.view_width + edgeInset.left + edgeInset.right, self.view_height + edgeInset.top + edgeInset.bottom); CGRect convertFrame = [self.superview convertRect:edgeFrame toView:self.superview]; if (CGRectContainsPoint(convertFrame, convertPoint)) { return self; } return [super hitTest:point withEvent:event];}@end
0 0
- UITextField添加点击高亮状态
- iOS_UItableVeiwCell 点击取消高亮状态
- 点击CListBox选中行外取消选中高亮状态
- storyboard中创建按钮点击时去掉高亮状态
- MVC点击菜单一直保持高亮状态
- iOS UIButton选中状态下点击高亮
- Android TextView 高亮字体并添加点击事件
- IOS 取消表格单元格 TableViewCell 去掉高亮状态 点击Cell取消选择状态
- 点击高亮!!!
- collection点击高亮...
- expandableListView点击高亮
- UITextField的点击事件
- UITextField点击选中文字
- 点击UITextField屏幕上移
- UITextField限制输入字数高亮状态下输入框内真实类容与textFiled(解决中文输入问题)
- UITextField添加内置图片
- AlertView中添加UITextField
- UITextField添加Block
- CS301n:Lecture2--线性分类
- 动态数组实现邻接表建图
- jenkins项目配置实例
- 精简搜狗输入法状态栏
- thinkphp 完整配置config.php
- UITextField添加点击高亮状态
- 10大html5前端框架
- JavaScriptSerializer 对象转字符串
- (转)设计模式六大原则
- C#播放音乐的5种方式
- ASP.NET的Cache缓存属性介绍
- 【<meta name="description" content=">】作用讲解
- 提升技术的记录方式
- ASP.NET Core 中文文档 第三章 原理(14)服务器