#import "ViewController.h"
#define font 17
@interface ViewController ()<UITextViewDelegate>
@property (weak, nonatomic) UITextView *textview;
@property (assign, nonatomic) BOOL isSelect;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self protocolIsSelect:self.isSelect];
}
- (void)protocolIsSelect:(BOOL)select {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"这里写文字"];
_textview = [[UITextView alloc] init];
UIImage *image = [UIImage imageNamed:@"icon_is"];
CGSize size = CGSizeMake(font + 2, font + 2);
UIGraphicsBeginImageContextWithOptions(size, false, 0);
[image drawInRect:CGRectMake(0, 2, size.width, size.height)];
UIImage *resizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = resizeImage;
NSMutableAttributedString *imageString = [NSMutableAttributedString attributedStringWithAttachment:textAttachment];
[imageString addAttribute:NSLinkAttributeName
value:@"checkbox://"
range:NSMakeRange(0, imageString.length)];
[attributedString insertAttributedString:imageString atIndex:23];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font] range:NSMakeRange(0, attributedString.length)];
_textview.attributedText = attributedString;
_textview.linkTextAttributes = @{NSForegroundColorAttributeName: [UIColor blueColor],
NSUnderlineColorAttributeName: [UIColor lightGrayColor],
NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid)};
_textview.delegate = self;
_textview.editable = NO;
_textview.scrollEnabled = NO;
_textview.frame = CGRectMake(100, 100, 280, 100);
[self.view addSubview:_textview];
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
if ([[URL scheme] isEqualToString:@"checkbox"]) {
NSLog(@"图片");
// self.isSelect = !self.isSelect;
// [self protocolIsSelect:self.isSelect];
return NO;
}
return YES;
}
@end
UITextView
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- UITextField : 只能输入一行,不可以滚动,可以设置提醒文字。 UITextView: 能输入多行,可以...
- //初始化并定义大小 UITextView *textview = [[UITextView alloc] ini...