当前位置: 首页 > news >正文

石家庄百度推广家庄网站建设wordpress设置仅自己可见

石家庄百度推广家庄网站建设,wordpress设置仅自己可见,节能网站源码,东莞南城网络公司一#xff0c;UICollectionView的简介 UICollectionView是iOS6之后引入的一个新的UI控件#xff0c;它和UITableView有着诸多的相似之处#xff0c;其中许多代理方法都十分类似。简单来说#xff0c;UICollectionView是比UITbleView更加强大的一个UI控件#xff0c;有如下…一UICollectionView的简介 UICollectionView是iOS6之后引入的一个新的UI控件它和UITableView有着诸多的相似之处其中许多代理方法都十分类似。简单来说UICollectionView是比UITbleView更加强大的一个UI控件有如下几个方面 1.支持水平和垂直两种方向的布局 2.通过layout配置方式进行布局 3.类似于TableView的cell特性外collectionView中的item大小和位置可以自由定义 4.通过layout布局回调的代理方法可以动态的定制每个item的大小和collection的大体布局属性 5.更加强大一点完全自定义一套layout布局方案可以实现意想不到的效果。设置静态的布局 实现一个最简单的九宫格类布局 - (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.//创建一个layout布局类UICollectionViewFlowLayout* flowLayout [[UICollectionViewFlowLayout alloc] init];flowLayout.scrollDirection UICollectionViewScrollDirectionVertical;//flowLayout.scrollDirection UICollectionViewScrollDirectionHorizontal;//flowLayout.itemSize CGSizeMake((self.view.frame.size.width - 80) / 3, (self.view.frame.size.width - 80) / 3);//flowLayout.itemSize CGSizeMake(100, 100 );//flowLayout.minimumLineSpacing 20;//flowLayout.minimumInteritemSpacing 20;flowLayout.sectionInset UIEdgeInsetsMake(20, 20, 20, 20);//创建collectionView通过一个布局策略layout来创建self.collectionView [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout];//注册cell[self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:cell];//设置代理self.collectionView.delegate self;//设置数据源self.collectionView.dataSource self;[self.view addSubview:self.collectionView]; }这里有一点需要注意collectionView在完成代理回调前必须注册一个cell类似如下: //注册cell[self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:cell];这和tableView有些类似又有些不同因为tableView除了注册cell的方法外还可以通过非注册的方法当复用池中没有可用的cell时可以返回nil然后重新创建。 //tableView在从复用池中取cell的时候有如下两种方法 //使用这种方式如果复用池中无是可以返回nil的我们在临时创建即可 - (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier; //6.0后使用如下的方法直接从注册的cell类获取创建如果没有注册 会崩溃 - (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);因为UICollectionView是iOS6.0之前的新类因此这里统一了从复用池中获取cell的方法没有再提供可以返回nil的方式并且在UICollectionView的回调代理中只能使用从复用池中获取cell的方式进行cell的返回其他方式会崩溃。 - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {UICollectionViewCell* cell [collectionView dequeueReusableCellWithReuseIdentifier:cell forIndexPath:indexPath];cell.backgroundColor [UIColor colorWithRed:arc4random() % 255 / 255.0 green:arc4random() % 255 / 255.0 blue:arc4random() % 255 / 255.0 alpha:1];return cell; }然后实现其他的代理方法 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {return 9; }上面我们写了一个简单九宫格的代码所有的item都是一样大小的但是有时候这样满足不了我们的需求我们有时候可能也需要item不同大小。 在上面代码的基础上删除控制item的大小的代码再加入下面几行代码即可实现 -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{if (indexPath.row % 2 0) {return CGSizeMake(50, 50);} else {return CGSizeMake(80, 80);} }设置动态布局 自定义FlowLayout进行瀑布流布局 首先我们新建一个文件继承于UICollectionViewFlowLayout #import UIKit/UIKit.hNS_ASSUME_NONNULL_BEGINinterface MyLayout : UICollectionViewFlowLayout property (nonatomic, assign)int itemCount; endNS_ASSUME_NONNULL_END前面说过UICollectionViewFlowLayout是一个专门用来管理collectionView布局的类因此collectionView在进行UI布局前会通过这个类的对象获取相关的布局信息FlowLayout类将这些布局信息全部存放在了一个数组中数组中是UICollectionViewLayoutAttributes类这个类是对item布局的具体设置以后咱们在讨论这个类。总之**FlowLayout类将每个item的位置等布局信息放在一个数组中在collectionView布局时会调用FlowLayout类layoutAttributesForElementsInRect方法来获取这个布局配置数组。因此我们需要重写这个方法返回我们自定义的配置数组**另外FlowLayout类在进行布局之前会调用prepareLayout方法所以我们可以重写这个方法在里面对我们的自定义配置数据进行一些设置。 简单来说自定义一个FlowLayout布局类就是两个步骤 1、设计好我们的布局配置数据 prepareLayout方法中 2、返回我们的配置数组 layoutAttributesForElementsInRect方法中 #import MyLayout.himplementation MyLayout {NSMutableArray* attributeArray; } - (void)prepareLayout {attributeArray [[NSMutableArray alloc] init];[super prepareLayout];float WIDTH ([UIScreen mainScreen].bounds.size.width - self.sectionInset.left - self.sectionInset.right - self.minimumInteritemSpacing) / 2;CGFloat colHeight[2] {self.sectionInset.top, self.sectionInset.bottom};for(int i 0; i self.itemCount; i) {NSIndexPath* index [NSIndexPath indexPathForItem:i inSection:0];UICollectionViewLayoutAttributes* attributes [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:index];CGFloat height arc4random() % 150 40;int width 0;if (colHeight[0] colHeight[1]) {colHeight[0] colHeight[0] height self.minimumLineSpacing;width 0;} else {colHeight[1] colHeight[1] height self.minimumLineSpacing;width 1;}attributes.frame CGRectMake(self.sectionInset.left (self.minimumInteritemSpacing WIDTH) * width, colHeight[width] - height - self.minimumLineSpacing, WIDTH, height);[attributeArray addObject:attributes];}if (colHeight[0] colHeight[1]) {self.itemSize CGSizeMake(WIDTH, (colHeight[0] - self.sectionInset.top) * 2 / self.itemCount - self.minimumLineSpacing);} else {self.itemSize CGSizeMake(WIDTH, (colHeight[1] - self.sectionInset.top) * 2 / self.itemCount - self.minimumLineSpacing);} } - (NSArray__kindof UICollectionViewLayoutAttributes * *)layoutAttributesForElementsInRect:(CGRect)rect {return attributeArray; } end 自定义完成FlowLayout后在View Controller中使用 #import ViewController.h #import MyLayout.h #import CollectionViewCell.h interface ViewController ()endimplementation ViewController- (void)viewDidLoad {[super viewDidLoad];MyLayout* layout [[MyLayout alloc] init];layout.scrollDirection UICollectionViewScrollDirectionVertical;layout.itemCount 100;UICollectionView* collectView [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];collectView.delegate self;collectView.dataSource self;[collectView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:cell];[self.view addSubview:collectView];// Do any additional setup after loading the view. } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {return 100; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {UICollectionViewCell* cell [collectionView dequeueReusableCellWithReuseIdentifier:cell forIndexPath:indexPath];cell.backgroundColor [UIColor colorWithRed:arc4random() % 255 / 255.0 green:arc4random() % 255 / 255.0 blue:arc4random() % 255 / 255.0 alpha:1];return cell; } end
http://www.pierceye.com/news/80779/

相关文章:

  • 杭州网站开发凡客长沙南站建站
  • 大连本站运营公司网站seo推广哪家值得信赖
  • python搭建网站制作的网站
  • 谁在万网建设的网站手机管理网站模板下载软件
  • 本地网站架设工具网站开发中涉及的侵权行为
  • 山东郓城网站建设wordpress被墙
  • 帮人做分销网站违法么vi设计哪些品牌比较好
  • 网站搭建 主机推荐网页制作模板ppt报告
  • 电商网站建设需要多少钱一年前端开发主要做什么
  • 海南网站备案wordpress加底纹
  • 怎么检查外包做的网站快速开发小程序
  • 咸阳做网站的公司有哪些青岛网站建设方案托管
  • 哪个网站可以帮忙做简历南京网站设计课程
  • 如何做公司培训网站2022最新引流推广平台
  • 公司没有备案了网站北京建设工程信息网上报名基础信息
  • 论坛网站建设多少钱怎样看一个网站做的网络广告
  • 那些网站可以接私活做网站开发技术与应用课程设计
  • 用asp.net做网站怎么打电话给网络服务商
  • 设计师都上什么网站2345浏览器免费版
  • 网站容量网站中英文转换怎么做
  • 潍坊高新建设局网站聊城网站建设项目
  • 逻辑网络设计的目标是什么?seo排名赚app
  • 定兴做网站建筑设计案例网站推荐
  • 博物馆网站页面设计说明从美洲开始做皇帝免费阅读网站
  • 长宁区科技网站建设好的网站建设方案
  • 汕尾网站网站建设私人网页制作
  • 网站提升排名台州城乡建设规划网站
  • 正常网站 月均ip pv中国纪检监察报社级别
  • WordPress腾讯云短信插件网站优化过度被k
  • 电子商务类网站嘉兴品牌网站建设