UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 100, 375, 100)];
textView.backgroundColor = [UIColor cyanColor];
//创建初始化文本的颜色,以及字体大小
NSDictionary *dictionary = @{NSFontAttributeName:[UIFont systemFontOfSize:17],NSForegroundColorAttributeName:[UIColor yellowColor]};
NSString * string = @" 跳转到百度\n\n 跳转到简书";
//创建富文本
NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:string attributes:dictionary];
//实现文本链接
[attributeStr addAttribute:NSLinkAttributeName value:@"http://www.jianshu.com" range:[string rangeOfString:@"简书"]];
[attributeStr addAttribute:NSLinkAttributeName value:@"http://www.baidu.com" range:[string rangeOfString:@"百度"]];
// textView.tintColor = [UIColor redColor];//调节文本链接字体的颜色
textView.attributedText = attributeStr;
textView.editable = NO;
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange return YES; }
//文本插入图片 NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNamed:@"red_2"]; //图片大小不合适 可以调整 attachment.bounds = CGRectMake(0, 0, 8, 8); NSMutableAttributedString *attachmentString = (NSMutableAttributedString *)[NSAttributedString attributedStringWithAttachment:attachment]; //你想要插入图片的位置 [textView.textStorage insertAttributedString:attachmentString atIndex:0]; [textView.textStorage insertAttributedString:attachmentString atIndex:10];
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有