NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:textString];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, textString.length)]; [attributedString addAttribute:NSKernAttributeName value:@1 range:NSMakeRange(0, textString.length)];
[attributedString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14],NSKernAttributeName: @1} range:NSMakeRange(0, textString.length)];
[attributedString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:26],NSForegroundColorAttributeName: [UIColor blueColor]} range:[textString rangeOfString:@"360云盘服务转型公告"]];
// 此方法可以通过string获得范围进行修改 NSRange startRange = [textString localizedStandardRangeOfString:@"我们即将采取以下措施:"]; NSRange endRange = [textString localizedStandardRangeOfString:@"感谢您的一路相伴。"]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSUnionRange(startRange, endRange)];
// 设置文本下划线 NSRange startRange1 = [textString localizedStandardRangeOfString:@"因此,"]; NSRange endRange1 = [textString localizedStandardRangeOfString:@"之后转型企业云服务。"]; [attributedString addAttribute:NSUnderlineStyleAttributeName value:@1 range:NSUnionRange(startRange1, endRange1)];
// 设置文本的描边 [attributedString addAttribute:NSStrokeWidthAttributeName value:@2.0 range:[textString rangeOfString:@"存储传播非法文件、侵权盗版牟利、传播淫秽色情信息等违法犯罪行为"]]; [attributedString addAttribute:NSStrokeColorAttributeName value:[UIColor brownColor] range:[textString rangeOfString:@"存储传播非法文件、侵权盗版牟利、传播淫秽色情信息等违法犯罪行为"]]; [attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:[textString rangeOfString:@"存储传播非法文件、侵权盗版牟利、传播淫秽色情信息等违法犯罪行为"]];
// 插入图片附件 NSTextAttachment *imageAtta = [[NSTextAttachment alloc] init]; imageAtta.bounds = CGRectMake(0, 0, 375, 180); imageAtta.image = [UIImage imageNamed:@"360"]; NSAttributedString *attach = [NSAttributedString attributedStringWithAttachment:imageAtta]; [attributedString insertAttributedString:attach atIndex:0];
// 段落样式 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; // 行间距 [style setLineSpacing:3]; // 段落间距 [style setParagraphSpacing:6]; // 首行缩进 [style setFirstLineHeadIndent:25]; [attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(1, textString.length)];
// 网址链接 NSRange urlRange = [textString rangeOfString:@"yunpan.360.cn"]; [attributedString addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://yunpan.360.cn"] range:NSMakeRange(urlRange.location, 14)]; [attributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(urlRange.location, 14)];
#pragma mark ----------UITextViewDelegate----------
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
NSLog(@"%@",URL);
return YES;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
NSLog(@"%@",textAttachment.image);
return YES;
}
// 字体 NSFontAttributeName // UIFont, default Helvetica(Neue) 12 // 段落 NSParagraphStyleAttributeName // NSParagraphStyle, default defaultParagraphStyle // 文字颜色 NSForegroundColorAttributeName // UIColor, default blackColor // 背景颜色 NSBackgroundColorAttributeName // UIColor, default nil: no background // 描边颜色 NSStrokeColorAttributeName // UIColor, default nil: same as foreground color // 描边宽度 NSStrokeWidthAttributeName // NSNumber containing floating point value, default 0 // 阴影 NSShadowAttributeName // NSShadow, default nil: no shadow // 附件 NSAttachmentAttributeName // NSTextAttachment, default nil // 链接URL NSLinkAttributeName // NSURL (preferred) or NSString // 基线偏移量 NSBaselineOffsetAttributeName // NSNumber containing floating point value,default 0 // 下划线 NSUnderlineColorAttributeName // UIColor, default nil: same as foreground color
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有