您的位置:首页 > 产品设计 > UI/UE

无限循环滚动大图(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开发