分段选择

#import "ViewController.h"
#import "MDMultipleSegmentView.h"
#import "MDFlipCollectionView.h"

@interface ViewController ()<MDMultipleSegmentViewDeletegate,
                            MDFlipCollectionViewDelegate>
{
    MDMultipleSegmentView *_segView;
    MDFlipCollectionView *_collectView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    _segView = [[MDMultipleSegmentView alloc] init];
    _segView.delegate =  self;
    _segView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 44);
    _segView.items = @[@"东",@"南", @"西", @"北", @"日", @"月"];
    [self.view addSubview:_segView];
   
    NSArray *arr = @[[self controller],
                     [self controller],
                     [self controller],
                     [self controller],
                     [self controller],
                     [self controller],

                    ];
   
    _collectView = [[MDFlipCollectionView alloc] initWithFrame:CGRectMake(0,
    CGRectGetMaxY(_segView.frame),
    CGRectGetWidth(_segView.frame),
    CGRectGetHeight(self.view.bounds) - CGRectGetMaxY(_segView.frame)) withArray:arr];
    _collectView.delegate = self;
    [self.view addSubview:_collectView];
}

- (UIViewController *)controller
{
    UIViewController *vc = [[UIViewController alloc] init];
    CGFloat red = arc4random() / (CGFloat)INT_MAX;
    CGFloat green = arc4random() / (CGFloat)INT_MAX;
    CGFloat blue = arc4random() / (CGFloat)INT_MAX;
    vc.view.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
    return vc;
}

- (void)changeSegmentAtIndex:(NSInteger)index
{
    [_collectView selectIndex:index];
}


- (void)flipToIndex:(NSInteger)index
{
    [_segView selectIndex:index];
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 838评论 0 0
  • 我相信一切都是命中注定。 各种巧合,各种机缘,造就不同的逸事。 我相信这都是上天安排。 在某个时间,某个地点 那个...
    蝉鸣夏阅读 374评论 0 2
  • 不是第一次在越秀公园看灯会,这么多人确实头一次。在不断上演脚尖睬脚跟的环境里,看得最多的是举手机拍照的人头。出图如下:
    xindong_ying阅读 196评论 0 1
  • 一 哥哥比英子大七岁,初中毕业后就...
    紫曼的紫_旭妈阅读 504评论 6 4
  • 这是我出生以来第一次遇到的公交事故,我将记录下这么难忘的一天。 今天约M去国贸看看,今早我们吃过早饭就出门乘公交了...
    曾琦阅读 179评论 0 0