textView的布局和点击事件
来源:互联网 发布:程序员都用github吗? 编辑:程序博客网 时间:2024/05/17 21:57
// - 设置 textView 不可以编辑
textView.editable =NO;
// - 设置文字的内边距
textView.textContainerInset =UIEdgeInsetsMake(0, -5,0, -5);
// - 设置 textView 不可以滚动
textView.scrollEnabled =NO;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 触摸对象
UITouch *touch = [touches anyObject];
// 触摸点
CGPoint point = [touch locationInView:self];
NSArray *specials = [self.attributedTextattribute:@"specials"atIndex:0effectiveRange:NULL];
BOOL contains = NO;
for (HWSpecial *specialin specials) {
self.selectedRange = special.range;
// self.selectedRange --影响--> self.selectedTextRange
// 获得选中范围的矩形框
NSArray *rects = [selfselectionRectsForRange:self.selectedTextRange];
// 清空选中范围
self.selectedRange =NSMakeRange(0,0);
for (UITextSelectionRect *selectionRectin rects) {
CGRect rect = selectionRect.rect;
if (rect.size.width ==0 || rect.size.height ==0) continue;
if (CGRectContainsPoint(rect, point)) {//点中了某个特殊字符串
contains = YES;
break;
}
}
if (contains) {
for (UITextSelectionRect *selectionRectin rects) {
CGRect rect = selectionRect.rect;
if (rect.size.width ==0 || rect.size.height ==0) continue;
UIView *cover = [[UIViewalloc]init];
cover.backgroundColor = [UIColorgreenColor];
cover.frame = rect;
cover.tag = HWStatusTextViewCoverTag;
cover.layer.cornerRadius =5;
[self insertSubview:cover atIndex:0];
}
break;
}
}
// 在被触摸的特殊字符串后面显示一段高亮的背景
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
[self touchesCancelled:toucheswithEvent:event];
});
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
// 去掉特殊字符串后面的高亮背景
for (UIView *childinself.subviews) {
if (child.tag ==HWStatusTextViewCoverTag) [childremoveFromSuperview];
}
}
- textView的布局和点击事件
- TextView 的点击事件
- Android自定义布局系列之一:流式布局(含TextView的点击事件)
- TextView 和 EditText 的 DrawableRight 点击事件的处理
- textview设置多种不同的字体颜色和点击事件
- RecyclerView添加点击事件和textView的超链接点击事件冲突
- textView autolink 和onclick 点击事件冲突
- 可滚动textView 和点击事件冲突
- textview的多种字体和一个textview中的多个点击事件
- 同一个TextView不同文字的点击事件
- Android之TextView------LINK的点击事件
- 给TextView添加点击事件的写法
- TextView设部分文字的点击事件
- TextView 点击事件无效的完美解决
- TextView点击事件
- ListView的Item里的TextView设置ClickableSpan和LinkMovementMethod导致ListView无法响应点击事件
- iOS中textView和textField键盘的return键点击事件
- TextView中的部分文字自定义颜色和点击事件(类似新浪微博带颜色的可点击字体)
- 最新版SDWebImage的使用
- 史上最全设计模式导学目录(完整版)
- mongodb基本使用
- 在Android代码中给布局添加控件
- 一个优秀的Android应用从建项目开始
- textView的布局和点击事件
- 芒果iOS开发UI课程第一节UIWindow
- Cocos2dx-OpenGL ES2.0教程:初识MVP(3)
- 关于sql语句,select查询时很快,加了top + 数字之后就会很慢
- C#数据库编程---事务回滚
- 网站前端素材网站
- Android程序通过Apache服务器执行PHP程序连接Mysql数据库(重要!)
- [Elasticsearch] 分布式文档存储
- 软键盘的显示问题 imeOptions