iOS红海新闻源码

2018-04-12  本文已影响84人  IT的救赎

本人工作之余写的一个红海新闻应用,MVC架构设计,项目虽然很小,但是五脏俱全。下面请先看看项目结构吧:

项目结构如图 

项目效果图 

新闻首页就不多说,是TableView实现,但是详情页面是富文本实现,具体代码如下: 

* //进行NSTextAttachment的创建 

NSTextAttachment * attach = [[NSTextAttachment alloc]init]; 

//设置显示的图片 

attach.image =self.model.image; 

//设置尺寸 

attach.bounds = CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width-20, self.model.ImageHeight); 

//创建文本NSAttributedString对象 

NSMutableAttributedString * attri = [[NSMutableAttributedString alloc]initWithString:self.model.content];* 

NSRange ragen = NSMakeRange(0, self.model.content.length);

[attri addAttribute:NSFontAttributeName

                      value:[UIFont systemFontOfSize:13.0]

                      range:ragen];

[attri addAttribute:NSUnderlineStyleAttributeName

              value:@(NSUnderlineStyleSingle)

              range:ragen];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

paragraphStyle.lineSpacing = 10;// 字体的行间距

paragraphStyle.firstLineHeadIndent = 40.0f;//首行缩进

paragraphStyle.paragraphSpacing = 15;//段与段之间的间距

paragraphStyle.paragraphSpacingBefore = 40.0f;//段首行空白空间

[attri addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:ragen];

//将NSTextAttachment映射为NSAttributedString对象

NSMutableAttributedString * att = [[NSMutableAttributedString alloc]initWithAttributedString:[NSAttributedString attributedStringWithAttachment:attach]];

//将图片插入NSAttributedString中

[attri insertAttributedString:att atIndex:100];

UITextView * label = [[UITextView alloc]init];

label.editable = NO;

label.backgroundColor = [UIColor clearColor];

label.attributedText = attri;

[self.view addSubview:label];

[label mas_makeConstraints:^(MASConstraintMaker *make) {

    make.top.equalTo(@(0));

    make.left.equalTo(@(10));

    make.bottom.equalTo(@(-10));

    make.right.equalTo(@(-10));

}];*

这是今年第一次写,希望以后多写写,现在把代码地址贴上:https://gitee.com/baishiyun/red_sea_news_app ,初学者可以看看,大牛勿喷!谢谢大家,觉得不错的请给一个星星吧!您的支持就是我前进的动力,以后会写更多文章供需要的朋友学习!谢谢!

上一篇下一篇

猜你喜欢

热点阅读