最近项目上要实现一个效果,先把效果图摆上来吧:

刚看到效果图的时候  我觉得很简单  用UICollectionview就可以了 但是后来发现collectionview只有两种布局方式  比较单一 :

箭头代表滑动方向

或者           

需求效果图:

方法:要实现刚才那个效果方法可能有很多解决方案  比如说重写UICollectionViewFlowLayout等方法 但这次用的方法相比于自定义UICollectionViewFlowLayout我觉得要简单一点那就是在添加一个scrollerview  在scrollerview添加view  在view上添加button:

附代码:

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong) UIPageControl *myPageControl;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addScrollerviewOnView];
}
//添加scrollerview和UIPageControl
- (void)addScrollerviewOnView{
UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
scrollview.delegate = self; scrollview.pagingEnabled = YES; scrollview.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width*, [UIScreen mainScreen].bounds.size.height);
scrollview.backgroundColor = [UIColor redColor];
for (int i = ; i<; i++) {
UIView *view = [[UIView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width*i, , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
view.tag = i;
[self addBtnWithView:view];
view.backgroundColor = [UIColor colorWithWhite:-i*0.3 alpha:];
[scrollview addSubview:view];
} [self.view addSubview:scrollview]; UIPageControl *pageControl = [[UIPageControl alloc] init]; self.myPageControl = pageControl; pageControl.center = CGPointMake(,); pageControl.bounds = CGRectMake(, , , ); pageControl.numberOfPages = ; pageControl.pageIndicatorTintColor = [UIColor greenColor]; pageControl.currentPageIndicatorTintColor = [UIColor blueColor]; [self.view addSubview:pageControl]; }
//在scrollerview上的viwe上面添加按钮
- (void)addBtnWithView:(UIView *)view{
for (int i = ; i<(view.tag<?:); i++) {
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((+(i%)*(([UIScreen mainScreen].bounds.size.width-)/+)), (+(i/)*(([UIScreen mainScreen].bounds.size.height-)/+)), ([UIScreen mainScreen].bounds.size.width-)/, ([UIScreen mainScreen].bounds.size.height-)/)];
btn.backgroundColor = [UIColor yellowColor];
[view addSubview:btn];
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)scrollViewDidScroll:(UIScrollView *)sender
{
CGFloat pageWidth = sender.frame.size.width;
int page = floor((sender.contentOffset.x - pageWidth / ) / pageWidth) + ;
self.myPageControl.currentPage = page; }

肯定会有更简单更好的实现方法  希望能够不吝赐教,联系我

通过scrollerview自定义collectionview(常用于推荐关注界面)的更多相关文章

  1. Xcode常用插件推荐

    1.Xcode插件管理工具–Alcatraz的安装 Alcatraz是针对Xcode的一款插件管理器,通过Alcatraz可以非常方便的管理插件,包括安装.删除.升级等操作. 官方网站 安装方法一(推 ...

  2. CollectionView常用的布局方式总结

    结合网上的collectionView常用布局整合的collectionView使用工具 下载地址 支持五种布局方式ZFCollectionViewLayoutType有两种ZFCollectionV ...

  3. Chrome浏览器与常用插件推荐

    Chrome浏览器与常用插件推荐 官方chrome下载:http://www.google.cn/chrome/ 提示:需要FQ才能安装. 1,AdBlock 谷歌屏蔽广告: https://chro ...

  4. iOS不得姐项目--推荐关注模块(一个控制器控制两个tableView),数据重复请求的问题,分页数据的加载,上拉下拉刷新(MJRefresh)

    一.推荐关注模块(一个控制器控制两个tableView) -- 数据的显示 刚开始加载数据值得注意的有以下几点 导航控制器会自动调整scrollView的contentInset,最好是取消系统的设置 ...

  5. ATOM常用插件推荐

    转载:http://blog.csdn.net/qq_30100043/article/details/53558381 ATOM常用插件推荐 simplified-chinese-menu ATOM ...

  6. Mac 常用软件推荐

    1.常用软件推荐 这里推荐的 apps 在开发者圈子内普遍评价不错,能便利的处理日常的开发和使用的任务.以下推荐分为四类: 开发者工具 生产力工具 办公工具 其他 2.Developer Tools ...

  7. ubuntu安装和常用软件推荐

    ubuntu安装和常用软件推荐(个人整理) 2016.08.22 17:29 13811浏览 字号 安装一套双系统,win10打游戏,ubuntu开发,win10放机械,ubuntu放固态,电脑联想i ...

  8. 【编程工具】Sublime Text3的安装和常用插件推荐

    本人刚刚学习 HTML,曾经上网找过一些编写 HTML 的软件,但感觉都不太好,经过三挑四选下,最终我决定选择 Sublime Text3 这款软件来作为学习工具,上网找到了许多实用的插件,在这里给大 ...

  9. Django 编写自定义的 404 / 500 报错界面

    Django 编写自定义的 404 / 500 报错界面 1. 首先 setting.py 文件中的 debug 参数设置成 false ,不启用调试. DEBUG = False 2. 在 temp ...

随机推荐

  1. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.4

    If $\dim \scrH=3$, then $\dim \otimes^3\scrH =27$, $\dim \wedge^3\scrH =1$ and $\dim \vee^3\scrH =10 ...

  2. Uva11732(trie)

    题意:给你n个字符串 用strcmp()两两比较 ,求字符比较的总次数 分析: 数据量很大我们考虑用孩子兄弟表示法来表示字典树 #include <cstdio> #include < ...

  3. 手把手教你写对拍程序(PASCAL)

    谁适合看这篇文章? ACMERS,OIERS或其它参加算法竞赛或需要算法的人 对操作系统并不太熟悉的人 不会写对拍的人 在网上找不到一个特别详细的对拍样例的人 不嫌弃我写的太低幼的人 前言 在NOIP ...

  4. 安装zabbix server

    本文安装的zabbix版本为2.2 步骤 1.安装php 5.3.3 rpm -e `rpm -qa | grep php` rpm -ivh http://mirrors.163.com/cento ...

  5. Good practice release jar to Nexus

    Step  suppose you need to develop a feature,when you finish the feature ,you need to release the jar ...

  6. HW5.27

    public class Solution { public static void main(String[] args) { int totalCount = 0; int lineCount = ...

  7. yum cdh4

    cdh4 install for Centos6那个最美的年代,最好的时光,一路梦想,一路流泪,流的不会是懦弱的泪,而是对奋斗的寄于;1,repo配置>>>/etc/yum.repo ...

  8. Mysql安装详解

    1.MySQL三种安装方式 Rpm包安装 免编译二进制包安装 源码编译安装 1.1.安装环境 Red Hat Enterprise Linux Server release 6.4 2.安装介绍 2. ...

  9. 用Modelsim仿真QuartusII综合后网表时库的添加方法(转)

    这两天做综合后仿真,发现FPGA器件库又不会加了,无奈上网找方法.说起来不好意思,很早就接触Modelsim这个仿真软件了,可是没有好好琢磨.把这两天找的方法贴出来,再加上自己的理解,以后忘了可以上博 ...

  10. 【C++深入浅出】设计模式学习之单例模式

    但凡成为大家公认的模式,都是有一些不可小觑的威力,今天分享一个简单的设计模式:单例模式. 单例模式用于一些只希望有一个实例的类或者只希望执行一次的操作:校长只能有一个.老板只能有一个.用户点击弹窗只希 ...