这次介绍请求下来一篇文章的数据后,做一个文章的展示界面,实现图文混排,效果如下:
文章的内容是一页一页显示的,标题也会一直在文章内容的上方,移动的时候会有动态效果。
网络请求之后,文章的内容先要做本地化处理,使用的时候先把文件夹RSReadingBoard 导入
使用的时候 先导入
#import "RSArticle.h"
#import "RSReadingBoard.h"
然后根据自己的需要写入代码,比如:
RSReadingBoard *board = [RSReadingBoard board];
RSArticle *article = [RSArticle new];
article.image = [UIImage imageNamed:@"image"];
article.title = @"这是标题";
article.source = @"文章的来源";
article.date = @"日期:March 25, 2014 -- Updated 1129 GMT (1929 HKT)";
article.body = [NSString stringWithContentsOfFile:[[[NSBundle mainBundle] URLForResource:@"Body" withExtension:@"txt"] path] encoding:NSUTF8StringEncoding error:nil];
article.color = [UIColor blackColor];
article.clips = @[[UIImage imageNamed:@"clip0"],
[UIImage imageNamed:@"clip1"],
[UIImage imageNamed:@"clip2"]];
board.article = article;
这个框架的实现原理是在RSReadingBoard类中用 xib 实现排版,
定义类目UIImage+Fitness:得到方法:
- (UIImage *)imageWithNewSize:(CGSize)newSize
horizontalAlignment:(RSHorizontalAlignment)horizontalAlignment
verticalAlignment:(RSVerticalAlignment)verticalAlignment
scale:(CGFloat)scale;
来实现图片的排版。