SLPagingView@kennygunie 0.0.6

SLPagingView@kennygunie 0.0.6

测试测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2015年5月

Kien NGUYEN 维护。



  • StefanLage 和 Kien NGUYEN

SLPagingView

一个导航栏系统,允许执行像 Tinder 或 Twitter 风格的操作。

要求

  • iOS 7.0+
  • ARC

安装

手动操作

将 SLPagingView 文件夹导入到您的项目中。

如何使用

易于实现

    // Make views for the navigation bar
    UIImage *img1 = [UIImage imageNamed:@"gear"];
    img1 = [img1 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

    UIImage *img2 = [UIImage imageNamed:@"profile"];
    img2 = [img2 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

    UIImage *img3 = [UIImage imageNamed:@"chat"];
    img3 = [img3 imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

    NSArray *titles = @[[[UIImageView alloc] initWithImage:img1], [[UIImageView alloc] initWithImage:img2], [[UIImageView alloc] initWithImage:img3]];
    NSArray *views = @[[self viewWithBackground:orange], [self viewWithBackground:[UIColor yellowColor]], [self viewWithBackground:gray]];

    SLPagingViewController *pageViewController = [[SLPagingViewController alloc] initWithNavBarItems:titles
                                                                                    navBarBackground:[UIColor whiteColor]
                                                                                               views:views
                                                                                     showPageControl:NO];

然后您可以定义自己的行为

    // Tinder Like
    pageViewController.pagingViewMovingRedefine = ^(UIScrollView *scrollView, NSArray *subviews){
        int i = 0;
        for(UIImageView *v in subviews){
            UIColor *c = gray;
            if(v.frame.origin.x > 45
               && v.frame.origin.x < 145)
                // Left part
                c = [self gradient:v.frame.origin.x
                               top:46
                            bottom:144
                              init:orange
                              goal:gray];
            else if(v.frame.origin.x > 145
                    && v.frame.origin.x < 245)
                // Right part
                c = [self gradient:v.frame.origin.x
                               top:146
                            bottom:244
                              init:gray
                              goal:orange];
            else if(v.frame.origin.x == 145)
                c = orange;
            v.tintColor= c;
            i++;
        }
     };

其他示例

像 Twitter 一样的行为

    // Twitter Like
    pageViewController.pagingViewMovingRedefine = ^(UIScrollView *scrollView, NSArray *subviews){
        CGFloat xOffset = scrollView.contentOffset.x;
        int i = 0;
        for(UILabel *v in subviews){
            CGFloat alpha = 0.0;
            if(v.frame.origin.x < 145)
                alpha = 1 - (xOffset - i*320) / 320;
            else if(v.frame.origin.x >145)
                alpha=(xOffset - i*320) / 320 + 1;
            else if(v.frame.origin.x == 140)
                alpha = 1.0;
            i++;
            v.alpha = alpha;
        }
    };

API

设置当前页面

如果想要更改默认页面控制索引(或任何其他),可以调用

    -(void)setCurrentIndex:(NSInteger)index animated:(BOOL)animated;

导航项样式

您可以通过设置导航项来轻松定制

    @property (nonatomic) SLNavigationSideItemsStyle navigationSideItemsStyle;

使用以下值之一

    typedef NS_ENUM(NSInteger, SLNavigationSideItemsStyle) {
        SLNavigationSideItemsStyleOnBounds,
        SLNavigationSideItemsStyleClose,
        SLNavigationSideItemsStyleNormal,
        SLNavigationSideItemsStyleFar,
        SLNavigationSideItemsStyleDefault,
        SLNavigationSideItemsStyleCloseToEachOne
    };

设置导航栏的背景颜色

您可以使用以下方法更新导航栏的背景颜色

    setNavigationBarColor:(UIColor*) color;

Storyboard 支持

这个类可以使用 Storyboard 实现。您需要设置与您的 SLPagingViewController 相连的所有 segue 的标识符,遵守以下语法: sl_X where X ∈ [0..N]

X 对应视图的索引,从 0 开始,按升序排列。

segue

您可以在 "TinderStoryboard" 示例中找到更多信息。

设置导航栏的背景颜色

要设置 Storyboard 中的导航栏背景颜色,就像为所有导航栏设置一样。

segue

许可证

在 MIT 许可证下可用,请查阅 LICENSE 获取更多信息。