实现图文混编界面
// // ViewController.m // GCD多线程 // // Created by 张凯泽 on 16/3/9. // Copyright © 2016年 rytong_zkz. All rights reserved. // #import "ViewController.h" #import "ZKZTextAttachment.h" @interface ViewController ()<UITextViewDelegate> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITextView * textView = [[UITextView alloc]initWithFrame:self.view.frame]; textView.delegate = self; [self.view addSubview:textView]; //textView.userInteractionEnabled = NO; ZKZTextAttachment * attachment = [[[ZKZTextAttachment alloc]init]init]; attachment.image = [UIImage imageNamed:@"1.png"]; NSMutableAttributedString * attachmentString = (NSMutableAttributedString *)[NSAttributedString attributedStringWithAttachment:attachment]; [textView.textStorage appendAttributedString:attachmentString]; NSAttributedString * attachmentString1 = [[NSAttributedString alloc]initWithString:@"我饿我饿隔日 i 个本日 ver 好哦围观喝哦让别人弄不好v 会玩弄别惹您别人v 饿噢人不会热哦不容v 我呢热播如同被 one 女保暖热播女人旅呢哦日本呢肉搏王府井沛公就碰上个人评价饿哦让格局哦尔和包容他不会肉片;电话费都多家品牌非得哦 if 和哦哦的非农尔附近包容他人就播饿啊跑哦嗯热播耳机"]; [textView.textStorage appendAttributedString:attachmentString1]; } -(BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange { NSLog(@"___________"); return YES; } -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { } @end
// // ZKZTextAttachment.h // GCD多线程 // // Created by 张凯泽 on 16/3/9. // Copyright © 2016年 rytong_zkz. All rights reserved. // #import <UIKit/UIKit.h> @interface ZKZTextAttachment : NSTextAttachment @end
// // ZKZTextAttachment.m // GCD多线程 // // Created by 张凯泽 on 16/3/9. // Copyright © 2016年 rytong_zkz. All rights reserved. // #import "ZKZTextAttachment.h" @implementation ZKZTextAttachment -(CGRect)attachmentBoundsForTextContainer:(NSTextContainer *)textContainer proposedLineFragment:(CGRect)lineFrag glyphPosition:(CGPoint)position characterIndex:(NSUInteger)charIndex { CGRect rect = CGRectMake(0, 0, 320, 200); return rect; } @end
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步