Coder Social home page Coder Social logo

ypsegmentcontroller's Introduction

YPSegmentController

CI Status Version License Platform

Example

demo1

目前完成功能:

  • 1.滑动模式 Normal
  • 2.滑动模式 Center
  • 3.颜色渐变
  • 4.文字大小渐变
  • 5.滑动进度模式Progress

使用说明书

最简单的集成方式

  • 1.首先引入YPSegmentController.h头文件
  • 2.将segmentController作为weak属性
  • 3.将segmentController作为当前控制器的子控制器
  • 4.将segmentController的view加到当前控制器的子视图
  • 5.创建若干子控制器,调用-[YPSegmentController setUpWithItems:]方法添加.
#import "ViewController.h"
#import "YPSegmentController.h"
#import "UIView+YPSegment.h"
#import "YPMeituanDemoViewController.h"

#define YPColor_RGB(r, g, b) [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:1.0]
#define YPRandomColor_RGB YPColor_RGB(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

@interface ViewController ()

@property (nonatomic, weak) YPSegmentController *segmentController;

@end

@implementation ViewController

#pragma mark - Lazy

- (YPSegmentController *)segmentController
{
    if (!_segmentController) {
        YPSegmentController *vc = [YPSegmentController new];
        [self addChildViewController:vc];
        _segmentController = vc;
    }
    return _segmentController;
}

#pragma mark - Cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"2016互联网十强企业";
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.segmentController.view.frame = self.view.bounds;
    [self.view addSubview:self.segmentController.view];
    
    UIViewController *vc1 = [UIViewController new];
    vc1.title = @"腾讯";
    vc1.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc2 = [UIViewController new];
    vc2.title = @"阿里巴巴";
    vc2.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc3 = [UIViewController new];
    vc3.title = @"蚂蚁金服";
    vc3.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc4 = [UIViewController new];
    vc4.title = @"百度";
    vc4.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc5 = [UIViewController new];
    vc5.title = @"京东";
    vc5.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc6 = [UIViewController new];
    vc6.title = @"网易";
    vc6.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc7 = [UIViewController new];
    vc7.title = @"小米科技";
    vc7.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc8 = [UIViewController new];
    vc8.title = @"滴滴出行";
    vc8.view.backgroundColor = YPRandomColor_RGB;
    UIViewController *vc9 = [UIViewController new];
    vc9.title = @"陆金所";
    vc9.view.backgroundColor = YPRandomColor_RGB;
    YPMeituanDemoViewController *vc10 = [YPMeituanDemoViewController new];
    vc10.title = @"美团-大众点评";
    
    
    [self.segmentController setUpWithItems:@[vc1,vc2,vc3,vc4,vc5,vc6,vc7,vc8,vc9,vc10]];

}

@end

@property (nonatomic, weak) YPSegmentController *segmentController;

YPSegmentBar.h

#import <UIKit/UIKit.h>
#import "YPSegmentBarConfig.h"


typedef NS_ENUM(NSInteger, YPSegmentBarScrollMode) {
    YPSegmentBarScrollModeNormal, // 默认滚动模式
    YPSegmentBarScrollModeCenter  // 中间滚动模式
};

typedef NS_ENUM(NSInteger, YPSegmentBarLinkMode) {
    YPSegmentBarLinkModeNormal, // 默认联动模式
    YPSegmentBarLinkModeProgress  // 根据进度的联动模式
};

@protocol YPSegmentBarDelegate;

@interface YPSegmentBar : UIView


/** 数据源 */
@property (nonatomic, copy) NSArray <NSString *> *items;

/** 代理 */
@property (nonatomic, weak) id <YPSegmentBarDelegate> delegate;

/** 当前选中的索引, 双向设置 */
@property (nonatomic, assign) NSInteger selectIndex;

/** 滚动模式 */
@property (nonatomic, assign) YPSegmentBarScrollMode scrollMode;

/** 联动模式 */
@property (nonatomic, assign) YPSegmentBarLinkMode linkMode;

/** 指示器进度 */
@property (nonatomic, assign) CGFloat indicatorProgress;

/** 是否开启标题颜色渐变 默认为No */
@property (nonatomic, assign) BOOL enableTitleColorGradient;

/** 是否开启标题大小渐变 默认为No */
@property (nonatomic, assign) BOOL enableTitleSizeGradient;

/**
 *  配置Bar的各种参数
 */
- (void)updateWithConfig:(void(^)(YPSegmentBarConfig *config))block;

@end

@protocol YPSegmentBarDelegate <NSObject>

- (void)segmentBar:(YPSegmentBar *)segmentBar didSelectedIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex;

@end

UIKIT_EXTERN NSString * const YPSegmentBarSelectionDidChangeNotification;

YPSegmentController.h

#import <UIKit/UIKit.h>
#import "YPSegmentBar.h"
#import "YPSegmentControllerConfig.h"

NS_ASSUME_NONNULL_BEGIN

@interface YPSegmentController : UIViewController

/** 选项条 */
@property (nonatomic, weak) YPSegmentBar *segmentBar;

/** 是否开启预加载功能 */
@property (nonatomic, assign) BOOL prefetchingEnabled;

/** 背景View */
@property (nonatomic, weak) UIView *backgroundView;

/** 
 *  设置数据源
 */
- (void)setUpWithItems:(NSArray <UIViewController *>*)items;

/**
 *  修改基本配置
 */
- (void)updateWithConfig:(void(^)(YPSegmentControllerConfig *config))block;


@end

@interface UIViewController (YPSegmentControllerItem)

@property(nullable, nonatomic,readonly,strong) YPSegmentController *segmentController;

@end

NS_ASSUME_NONNULL_END

Requirements

Installation

YPSegmentController is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "YPSegmentController"

Author

MichaelHuyp, [email protected]

License

YPSegmentController is available under the MIT license. See the LICENSE file for more info.

ypsegmentcontroller's People

Contributors

michaelhuyp avatar

Stargazers

 avatar LJAYA avatar  avatar  avatar  avatar  avatar YoonAngel avatar WenHui BA avatar Mr.Z avatar TGod avatar Marvin avatar  avatar Booming Young avatar Bobby avatar MohsinAli avatar yanghengzhan avatar 蒋轩哲 avatar zedxpp avatar  avatar TempUser avatar  avatar

Watchers

James Cloos avatar MohsinAli avatar  avatar

ypsegmentcontroller's Issues

内存泄露

有个需求,登录后,需要替换控制器,在UIViewcontroller被释放掉后,YPSegmentController依然存在于内存中,造成内存泄露,麻烦看一下怎么处理?

How to scroll to specific segment (first page) programmatically?

For example in the readme, there are 10 pages for 10 companies, when I scroll to page 5, then there is no content and I set up a button which can direct to page 1 after click, how to implement scrolling to page 1?

I saw

- (void)segmentBar:(YPSegmentBar *)segmentBar didSelectedIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex
{
    [self showChildVCViewsAtIndex:toIndex];
}

but showChildVCViewsAtIndex() is not a public function.

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.