//
//  ViewController.m
//  WSFSlideTitlesView
//
//  Created by WangShengFeng on 3/7/16.
//  Copyright 漏 2016骞?WangShengFeng. All rights reserved.
//

#import "ViewController.h"

#import "WSFSlideTitlesView.h"

@interface ViewController () <WSFSlideTitlesViewDelegate>

@property (nonatomic, weak) WSFSlideTitlesView *titlesView;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 鍒涘缓 WSFSlideTitlesView
    [self createWSFSlideTitlesView];
    
    // 涓存椂鍒涘缓涓€涓寜閽慨鏀归€変腑鎸夐挳
    [self createSelectButton];
}

- (void)createWSFSlideTitlesView
{
    // 鍒涘缓璁剧疆锛屾渶灏戦渶瑕佸唴瀹瑰拰灏哄
    // 鍏朵粬鏍峰紡鑷畾涔夊彲鏌ョ湅 setting 澶存枃浠?    WSFSlideTitlesViewSetting *titlesSetting = [[WSFSlideTitlesViewSetting alloc] init];
    titlesSetting.titlesArr = @[ @"棣栭〉", @"娑堟伅", @"鍙戠幇", @"鎴?, ];
    titlesSetting.frame = CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 30);
    
    // 閫氳繃璁剧疆鍒涘缓 WSFSlideTitlesView
    WSFSlideTitlesView *titlesView = [[WSFSlideTitlesView alloc] initWithSetting:titlesSetting];
    titlesView.delegate = self;
    self.titlesView = titlesView;
    [self.view addSubview:titlesView];
}

- (void)createSelectButton
{
    UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [selectButton setTitle:@"閫変腑绗?0 涓寜閽? forState:UIControlStateNormal];
    [selectButton addTarget:self action:@selector(selectButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [selectButton sizeToFit];
    selectButton.center
    = CGPointMake([UIScreen mainScreen].bounds.size.width / 2, [UIScreen mainScreen].bounds.size.height / 2);
    
    [self.view addSubview:selectButton];
}

- (void)selectButtonClick
{
    // 鍦ㄥ閮ㄦ帶鍒跺唴閮ㄩ€変腑鎸夐挳锛屼紶鍏?index 鍗冲彲
    [self.titlesView selectButtonAtIndex:0];
}

- (void)slideTitlesView:(WSFSlideTitlesView *)titlesView didSelectButton:(UIButton *)button atIndex:(NSUInteger)index
{
    // 閫変腑鎸夐挳鍒囨崲閫氱煡澶栭儴
    NSLog(@"鐐瑰嚮 -绗?zd涓? -%@- 鎸夐挳", index, [button attributedTitleForState:UIControlStateNormal].string);
}




@end
// 鐗堟潈灞炰簬鍘熶綔鑰?// http://code4app.com (cn) http://code4app.net (en)
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜綉绔? Code4App.com