UILabel设置属性字符串,可以增加点击事件点击
2017-12-29 11:46
405 查看
1.首先啊,label可以设置属性字符串,设置不同的字体颜色,字体大小,但是要增加点击事件,不好操作。
2.所以文章是设置textView来完成的。
- (UITextView *)textView {
if (!_textView) {
_textView = [[UITextView alloc] init];
// NSMutableAttributedString *attributedString = [NSString attributuStringWithString:self.descText lineSpacing:10];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"1.您可能很久未更新最新数据导致图表有误,请及时刷新;\n以上分析根据公积金官网数据统计分析所得,可能存在有误。"];
[attributedString addAttribute:NSLinkAttributeName
value:@"ProvidentFundshuaxin://"
range:[[attributedString string] rangeOfString:@"刷新"]];
[attributedString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]} range:[self.descText rangeOfString:@"刷新"]];
_textView.attributedText = attributedString;
_textView.linkTextAttributes = @{NSForegroundColorAttributeName: ColorFromHexRGB(0xe73c00),
NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};
_textView.textColor = ColorFromHexRGB(0xa0a0a0);
_textView.delegate = self;
_textView.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
_textView.scrollEnabled = NO;
// NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
// paragraphStyle.lineSpacing = 20;// 字体的行间距
// NSDictionary *attributes = @{
// NSFontAttributeName:[UIFont systemFontOfSize:12],
// NSParagraphStyleAttributeName:paragraphStyle
// };
// _textView.typingAttributes = attributes;
// _textView.layer.borderColor = [UIColor cyanColor].CGColor;
// _textView.layer.borderWidth = 1.0f;
}
return _textView;
}
textView代理事件
-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
NSRange range = [@"1.您可能很久未更新最新数据导致图表有误,请及时刷新;\n以上分析根据公积金官网数据统计分析所得,可能存在有误。" rangeOfString:@"刷新"];
if (NSEqualRanges(characterRange, range)) {
NSLog(@"设置您的自定义事件");
// if (self.refreshAccountBlock) {
// self.refreshAccountBlock();
// }
}
return YES;
}
ok 完美解决。
2.所以文章是设置textView来完成的。
- (UITextView *)textView {
if (!_textView) {
_textView = [[UITextView alloc] init];
// NSMutableAttributedString *attributedString = [NSString attributuStringWithString:self.descText lineSpacing:10];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"1.您可能很久未更新最新数据导致图表有误,请及时刷新;\n以上分析根据公积金官网数据统计分析所得,可能存在有误。"];
[attributedString addAttribute:NSLinkAttributeName
value:@"ProvidentFundshuaxin://"
range:[[attributedString string] rangeOfString:@"刷新"]];
[attributedString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13]} range:[self.descText rangeOfString:@"刷新"]];
_textView.attributedText = attributedString;
_textView.linkTextAttributes = @{NSForegroundColorAttributeName: ColorFromHexRGB(0xe73c00),
NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};
_textView.textColor = ColorFromHexRGB(0xa0a0a0);
_textView.delegate = self;
_textView.editable = NO; //必须禁止输入,否则点击将弹出输入键盘
_textView.scrollEnabled = NO;
// NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
// paragraphStyle.lineSpacing = 20;// 字体的行间距
// NSDictionary *attributes = @{
// NSFontAttributeName:[UIFont systemFontOfSize:12],
// NSParagraphStyleAttributeName:paragraphStyle
// };
// _textView.typingAttributes = attributes;
// _textView.layer.borderColor = [UIColor cyanColor].CGColor;
// _textView.layer.borderWidth = 1.0f;
}
return _textView;
}
textView代理事件
-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
NSRange range = [@"1.您可能很久未更新最新数据导致图表有误,请及时刷新;\n以上分析根据公积金官网数据统计分析所得,可能存在有误。" rangeOfString:@"刷新"];
if (NSEqualRanges(characterRange, range)) {
NSLog(@"设置您的自定义事件");
// if (self.refreshAccountBlock) {
// self.refreshAccountBlock();
// }
}
return YES;
}
ok 完美解决。
相关文章推荐
- C# WinForm窗体的TopMost属性设置为true时,多次点击窗体弹出事件,只会弹出一个窗体
- 给TextView的drawableRight属性设置点击事件
- textview设置属性autolink后,点击网址链接如何捕捉到点击事件或者如何让其跳转到特定的app activity中
- android textview可以设置文字颜色 部分文字点击事件处理
- Android中EditText的drawableRight属性设置点击事件
- Cocos2d-x设置吞没单击属性来避免精灵重叠被点击后的事件续传
- 有一个图书馆系统,含有Book和BookMaster两个类。Book可以用来设置书的属性(如title),BookMaster每天做的事情就是根据上级的要求重设设定某些书的title,以增加借阅者的注意力,让更多的人对书有新的兴趣
- 给EditText的drawableRight属性的图片设置点击事件
- form表单元素设置disabled属性后支持点击click事件
- 如何为一个按钮(View)设置任意多次点击事件以及可以同时响应多个多次点击事件
- Flex中如何通过设置restrict属性在TextInput控件中限制用户可以输入的字符串的例子
- Android Button 常用属性设置,圆角,边框,点击事件
- 给EditText的drawableRight属性的图片设置点击事件 分类: 学习笔记 android 2015-07-06 13:20 134人阅读 评论(0) 收藏
- ListView集合中设置标记 setTag();方法带一个参数和两个参数的区别,以及设置标记时ViewHolder中的每一个属性控件都需要设置一次,否则在Item中每一个控件的点击事件中取出设置的标
- IOS UILabel 增加点击事件。
- 给EditText的drawableRight属性的图片设置点击事件
- 给EditText的drawableRight属性的图片设置点击事件
- 给EditText的drawableRight属性的图片设置点击事件
- 利用runtime懒人实现iOS 防止按钮连续点击 连续响应事件,可以自己设置时间间隔,拖进工程中立即生效
- 在MapView中增加Point,并可以响应点击事件