iOS开发UI篇—无限轮播(新闻数据展示)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了iOS开发UI篇—无限轮播(新闻数据展示),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3172字,纯文字阅读大概需要5分钟。
内容图文
iOS开发UI篇—无限轮播(新闻数据展示)
一、实现效果
二、实现步骤
1.前期准备
(1)导入数据转模型的第三方框架MJExtension
(2)向项目中添加保存有“新闻”数据的plist文件
(3)导入用到的图片素材
2.步骤和代码
(1)新建一个数据模型
该模型的代码设计如下:
YYnews.h文件
1 // 2 // YYnews.h 3 // 08-无限滚动(新闻数据展示) 4 // 5 6 #import <Foundation/Foundation.h> 7 8@interface YYnews : NSObject 9 @property(nonatomic,copy)NSString *title; 10 @property(nonatomic,copy)NSString *icon; 11@end
(2)新建一个继承自UICollectionViewCell的类,用于自定义cell。
(3)新建一个xib文件,和自定义的cell做关联
代码设计如下:
YYcell.h文件
1 // 2 // YYcell.h 3 // 08-无限滚动(新闻数据展示) 4 // 5 6 #import <UIKit/UIKit.h> 7 8@class YYnews; 9@interface YYcell : UICollectionViewCell 10 @property(nonatomic,strong)YYnews *news; 11@end
YYcell.m文件
1 // 2 // YYcell.m 3 // 08-无限滚动(新闻数据展示) 4 // 5 6 #import " YYcell.h " 7 #import " YYnews.h " 8 9 @interface YYcell () 10 @property (weak, nonatomic) IBOutlet UILabel *label; 11 @property (weak, nonatomic) IBOutlet UIImageView *imageView; 1213@end14@implementation YYcell 1516 -(void)setNews:(YYnews *)news 17{ 18 _news=news; 19 self.label.text=news.title; 20 self.imageView.image=[UIImage imageNamed:news.icon]; 21} 2223@end
(4)在主控制器中的代码处理
YYViewController.m文件
1 // 2 // YYViewController.m 3 // 4 // 5 // Created by apple on 14-8-3. 6 // Copyright (c) 2014年 yangyong. All rights reserved. 7 // 8 9 #import " YYViewController.h " 10 #import " MJExtension.h " 11 #import " YYnews.h " 12 #import " YYcell.h " 13 14 #define YYIDCell @"cell" 1516@interface YYViewController ()<UICollectionViewDataSource,UICollectionViewDelegate> 17 @property (weak, nonatomic) IBOutlet UICollectionView *collectinView; 18 @property(nonatomic,strong)NSArray *news; 19@end2021@implementation YYViewController 2223#pragma mark-懒加载 24 -(NSArray *)news 25{ 26if (_news==nil) { 27 _news=[YYnews objectArrayWithFilename:@"newses.plist"]; 28 } 29return _news; 30} 31 - (void)viewDidLoad 32{ 33 [super viewDidLoad]; 34//注册cell 35// [self.collectinView registerClass:[YYimageCell class] forCellWithReuseIdentifier:YYCell];36 [self.collectinView registerNib:[UINib nibWithNibName:@"YYcell" bundle:nil] forCellWithReuseIdentifier:YYIDCell]; 3738} 3940#pragma mark- UICollectionViewDataSource 41//一共多少组,默认为1组42 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 43{ 44return1; 45} 46 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 47{ 48return self.news.count; 49} 5051 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 52{ 53 YYcell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:YYIDCell forIndexPath:indexPath]; 54 cell.news=self.news[indexPath.item]; 55return cell; 56} 5758#pragma mark-UICollectionViewDelegate 59@end
3.补充说明
原文:http://www.cnblogs.com/wendingding/p/3888797.html
内容总结
以上是互联网集市为您收集整理的iOS开发UI篇—无限轮播(新闻数据展示)全部内容,希望文章能够帮你解决iOS开发UI篇—无限轮播(新闻数据展示)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。