无限循环滚动大图(UICollectionView)
2015-07-19 12:42
411 查看
Model
<pre name="code" class="cpp">@interface MJNews : NSObject @property (copy, nonatomic) NSString *title; @property (copy, nonatomic) NSString *icon; @end
View(cell自定义)
@class MJNews; @interface MJNewsCell : UICollectionViewCell @property (nonatomic, strong) MJNews *news; @end @interface MJNewsCell() @property (weak, nonatomic) IBOutlet UILabel *titleLabel; @property (weak, nonatomic) IBOutlet UIImageView *iconView; @end @implementation MJNewsCell - (void)setNews:(MJNews *)news { _news = news; self.iconView.image = [UIImage imageNamed:news.icon]; // self.titleLabel.text = news.title; self.titleLabel.text = [NSString stringWithFormat:@" %@", news.title]; } @end
Ctrol
@interface MJViewController () <UICollectionViewDataSource, UICollectionViewDelegate> @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; @property (strong, nonatomic) NSArray *newses; @end @implementation MJViewController - (NSArray *)newses { if (!_newses) { self.newses = [MJNews objectArrayWithFilename:@"newses.plist"]; } return _newses; } - (void)viewDidLoad { [super viewDidLoad]; // 注册cell [self.collectionView registerNib:[UINib nibWithNibName:@"MJNewsCell" bundle:nil] forCellWithReuseIdentifier:@"news"]; [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:2500 inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO]; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.newses.count * 1000; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"news"; MJNewsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; cell.news = self.newses[indexPath.item % self.newses.count]; return cell; } @end
相关文章推荐
- iOS开发之路--微博“更多”页面
- iOS开发之路--微博骨架搭建
- IOS开发代码分享之获取启动画面图片的string
- IOS开发之路--C语言数组和字符串
- IOS开发代码分享之用nstimer实现倒计时功能
- IOS开发代码分享之设置UISearchBar的背景颜色
- ios开发之环境搭建-01
- 在开发iOS程序时对日期处理的总结
- iOS开发——keychain的使用
- iOS Graphics Technologies iOS 图形技术
- iOS开发异常错误总结
- 学习Objective-C:入门手册
- iOS开发 简单实现视频音频的边下边播
- iOS开发 — Quartz 2D知识点应用 (制作了一个Demo,源代码)
- ios开发对配置文件plist的操作
- iphone5和4的屏幕兼容问题
- 9秒的课程只为培养靠谱的IOS和HTML5开发人才而定制
- iOS开发学习笔记 1-0 开篇
- iOS开发学习笔记 2-1 C语言部分 初识C语言
- iOS开发学习笔记 2-2 C语言部分 类型、运算符与表达式