TextKit简单示例
生活随笔
收集整理的這篇文章主要介紹了
TextKit简单示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
TextKit簡單示例
?
效果
?
源碼
https://github.com/YouXianMing/Animations
// // TextKitLoadImageController.m // Animations // // Created by YouXianMing on 16/4/10. // Copyright ? 2016年 YouXianMing. All rights reserved. // #import "TextKitLoadImageController.h" #import "AttributedStringInitConfig+Constructor.h" #import "JSAnimatedImagesView.h" #import "UIView+SetRect.h" #import "GCD.h"@interface TextKitLoadImageController () <JSAnimatedImagesViewDataSource>@property (nonatomic, strong) JSAnimatedImagesView *JSView; @property (nonatomic, strong) NSArray *JSViewDataSource;@end@implementation TextKitLoadImageController- (void)setup {[super setup];NSString *str = @"這是發生在阿拉斯加麥肯萊國家公園的事,這個公園有日本的四國那么大,卻只有一個為觀光客開設的游客中心,位置就在原野正中央,公園唯一的一條道路上,每天都有許多觀光客利用這個游憩場所。\n這附近是北極地松鼠的棲息地,所以每當有觀光客下車,地松鼠就會跑過來討東西吃,完全不怕人,公園管理員一再呼吁游客不要喂食地松鼠,但不管來自哪個國家的人,看到可愛機伶的地松鼠,還是會忍不住丟東西給它們吃。\n有一年,公園里豎著一個奇怪的告示牌。為什么說它奇怪呢?因為這個告示牌只有十公分高,不彎腰下去的話根本看不到,牌子開頭就寫著:“地松鼠們!”原來,這是寫給地松鼠看的警告。\n“......你們再一直吃著人類給的食物,就會越來越胖,最后跑不動,就只好被金雕或是熊吃掉......”一想到好奇的觀光客發出苦笑的臉,讓我不禁莞爾。又想到在日本的動物園中,看到游客不斷地往熊的籠子里丟食物,掛在旁邊的“請勿喂食”標示,看起來是那么的無力。\n有人看到動物就自然而然想喂食,這種事情大家都清楚,但也有人率直的認為那是不對的行為。堅持真理是很辛苦的,不如多點想象空間,用小小的幽默來勸服人心。";NSTextStorage *storage = [[NSTextStorage alloc] initWithString:str attributes:[AttributedStringInitConfig heitiSC]];// 管理器NSLayoutManager *layoutManager = [NSLayoutManager new];[storage addLayoutManager:layoutManager];// 顯示的容器(與UITextView對應)NSTextContainer *textContainer = [NSTextContainer new];CGSize size = CGSizeMake(Width - 20, MAXFLOAT);textContainer.size = size;[layoutManager addTextContainer:textContainer];UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, Width - 20, self.contentView.height - 20)textContainer:textContainer];textView.scrollEnabled = YES;textView.layer.borderWidth = 0.5f;textView.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.15f].CGColor;textView.editable = NO;textView.selectable = NO;textView.layer.masksToBounds = NO;textView.showsVerticalScrollIndicator = NO;textView.layer.masksToBounds = YES;[self.contentView addSubview:textView];CGRect imagesFrame = CGRectMake(60, 38, textView.width - 60 * 2, 170);textContainer.exclusionPaths = @[[self bezierPathWithFrame:imagesFrame]];[GCDQueue executeInMainQueue:^{self.JSViewDataSource = @[[UIImage imageNamed:@"pic_1"],[UIImage imageNamed:@"pic_2"],[UIImage imageNamed:@"pic_3"],[UIImage imageNamed:@"pic_4"]];self.JSView = [[JSAnimatedImagesView alloc] initWithFrame:imagesFrame];self.JSView.alpha = 0.f;self.JSView.transitionDuration = 2.f;self.JSView.dataSource = self;self.JSView.layer.masksToBounds = YES;[textView addSubview:self.JSView];[UIView animateWithDuration:2.f animations:^{self.JSView.alpha = 1.f;}];} afterDelaySecs:0.5f]; }- (UIBezierPath *)bezierPathWithFrame:(CGRect)frame {return [UIBezierPath bezierPathWithRect:frame]; }- (NSUInteger)animatedImagesNumberOfImages:(JSAnimatedImagesView *)animatedImagesView {return self.JSViewDataSource.count; }- (UIImage *)animatedImagesView:(JSAnimatedImagesView *)animatedImagesView imageAtIndex:(NSUInteger)index {return self.JSViewDataSource[index]; }@end?
轉載于:https://www.cnblogs.com/YouXianMing/p/5375649.html
總結
以上是生活随笔為你收集整理的TextKit简单示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实现PageProcessor
- 下一篇: 第六章:继承和多态