使用UICollectionView制作滑动viewpage
来源:互联网 发布:土方工程量计算软件 编辑:程序博客网 时间:2024/05/21 02:48
代码如下:
#import "MSViewController.h"@interface CollectionCell : UICollectionViewCell@property (nonatomic, weak) UILabel *titleLabel;@end@implementation CollectionCell-(instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { UILabel *titleLabel = [[UILabel alloc] initWithFrame:self.bounds]; [titleLabel setTextAlignment:NSTextAlignmentCenter]; self.titleLabel = titleLabel; [self.contentView addSubview:self.titleLabel]; self.backgroundColor = [UIColor yellowColor]; } return self;}@end////////////////////////////////////////////////////////////////////////@interface MSViewController () <UICollectionViewDataSource>@property (nonatomic, weak) UICollectionView *collectionView;@end@implementation MSViewController- (void)viewDidLoad{ [super viewDidLoad]; //每项大小 CGSize itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, CGRectGetHeight(self.view.bounds)); UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; //设置哪种方向滚动 layout.itemSize = itemSize; UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; collectionView.backgroundColor = [UIColor whiteColor]; collectionView.dataSource = self; [collectionView registerClass:[CollectionCell class] forCellWithReuseIdentifier:@"Cell"]; self.collectionView = collectionView; [self.view addSubview:self.collectionView];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - UICollectionViewDataSource methods- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return 5;}// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifierCell = @"Cell"; CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierCell forIndexPath:indexPath]; cell.titleLabel.text = [NSString stringWithFormat:@"%d",indexPath.row]; return cell;}@end
效果:
1 1
- 使用UICollectionView制作滑动viewpage
- ViewPage(滑动视图)使用详解!
- [译]使用水平和垂直滑动的UICollectionView来制作粘性的行和列
- 使用ViewPage实现类launcher屏幕滑动
- 使用ViewPage实现类launcher屏幕滑动
- 使用ViewPage实现类launcher屏幕滑动
- 使用ViewPage实现类launcher屏幕滑动
- 使用ViewPage实现无缝左右循环滑动
- Android开发——ViewPage制作滑动导航界面
- android:TabHost和ViewPage多页滑动的使用
- ScrollView,ListView,ViewPage滑动到底的阴影,overScrollMode的使用
- viewpage禁止滑动--android
- ViewPage判断左右滑动
- viewpage禁止滑动--android
- ViewPage判断左右滑动
- ViewPage 屏蔽滑动事件
- ViewPage滑动冲突解决办法
- Android Viewpage禁止滑动
- vmware下openfiler的ip设置
- iOS发布app到App Store教程
- 一台电脑如何管理多个SSH KEY
- 21个数据科学家面试必须知道的问题和答案
- Rhino -- 基于java的javascript实现
- 使用UICollectionView制作滑动viewpage
- OVS网桥建立和连接管理
- Android实现调度任务的三种方式:TimerTask、ScheduledExecutorService、Handler
- java Android 中的字符串比较和double类型转换为两位小数点
- Android TextView系列--第一篇
- svn最终搭建
- 图片加载框架Glide使用详解
- Mysql分段统计简单数据信息例如年龄,省份,性别等等
- Linux常用命令大全