Code Monkey home page Code Monkey logo

mysementviewcontroller's Introduction

MYSlideViewController

效果图

===================================

目前在项目中需要品牌分类的功能,于是自己就封装了一个控制器,主要用到了UICollectionView和UIScrollView的组合,效果类似电商app的嗨购和蜜芽的滚动条,感觉还行就把我的思路和制作过程写下来给大家分享一下。

Paste_Image.png

首先,界面分析。 上半部分用的是UICollectionView 下半部分用的是UIScrollView

上半部分的UICollectionView的Item是可以动态配置的,随着字体的宽度决定的。

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat height = collectionView.frame.size.height;
CGFloat width = 0;
CGRect bgFrame = CGRectFromString(self.indicatorBgFrames[indexPath.row]);
width = bgFrame.size.width;
return CGSizeMake(width, height);
}

下半的是UIScrollView则写的有点复杂了,为了节省空间,控制器的个数当>=3的时候,只会显示3个。

Paste_Image.png

最后有2个代理方法恭你选择

- (void)slideViewController:(MYSlideViewController *)slideViewController didSelectViewIndex:(NSInteger)selectViewIndex;

- (BOOL)slideViewController:(MYSlideViewController *)slideViewController shouldSelectViewIndex:(NSInteger)selectViewIndex;

ps: 我是一个iOS的苦行僧,喜欢开源,平常也会在github上上传一些个人的项目,欢迎志同道合的朋友一起加入。 另外,如果我封装的这个控制器能帮到你,就star一下吧。

mysementviewcontroller's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.