码迷,mamicode.com
首页 > 其他好文 > 详细

设置分段导航器

时间:2016-04-13 18:46:16      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

一、设置分段导航器

在ViewController。m里写

- (void)viewDidLoad {

    [super viewDidLoad];

    [self creatView];  

}

// 设置页面

- (void)creatView{

    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithFrame:CGRectMake(5, 50, fDeviceWidth-10, 29)];

    [seg insertSegmentWithImage:@"按钮button" atIndex:0 animated:YES];

    [seg insertSegmentWithImage:@"标签label" atIndex:1 animated:YES];

    seg.tintColor = [UIColor redColor];

    seg.selectedSegmentIndex = 0;

    [seg addTarget:self action:@selector(seg:) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:seg];

// 初始化button 和 label 页面的位置

    _button = [[ButtonView alloc] initWithFrame:CGRectMake(0, 160, fDeviceWidth, fDeviceHeight)];

    [self.view addSubview:_button];

    _label = [[LabelView alloc] initWithFrame:CGRectMake(fDeviceWidth, 160, fDeviceWidth, fDeviceHeight)];

    [self.view addSubview:_label];  

}

// 页面之间的切换

- (void)seg:(UISegmentedControl *)Seg{

    if (Seg.selectedSegmentIndex == 0) {

        Seg.selectedSegmentIndex = 0;

        [UIView animateWithDuration:0.2 animations:^{

            _button.hidden = NO;

            _button.frame = CGRectMake(0, 80, fDeviceWidth, fDeviceHeight - 30) ;

            _label.frame = CGRectMake(fDeviceWidth, 50, fDeviceWidth, fDeviceHeight);

        }];

    }else{

        Seg.selectedSegmentIndex = 1;

        [UIView animateWithDuration:0.2 animations:^{

            _button.frame = CGRectMake(-fDeviceWidth, 50, fDeviceWidth, fDeviceHeight);

            _label.frame = CGRectMake(0, 80, fDeviceWidth, fDeviceHeight - 30) ;

            _button.hidden = YES; 

        }];  

    }  

}

二、设置导航的2个页面 button页面 和 label 页面

①、

_oneButton = [[UIButton alloc] initWithFrame:CGRectMake( 20, 20, 20, 20)];

    _oneButton.backgroundColor = [UIColor brownColor];

    [self addSubview:_oneButton];

 _twoButton = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];

    _twoButton.backgroundColor = [UIColor greenColor];

    [self addSubview:_twoButton];

 ②、

    _oneLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 90, 200, 30)];

    _oneLabel.text = @"只要功夫深";

    _oneLabel.font = [UIFont systemFontOfSize:13];

    [self addSubview:_oneLabel];

 _twoLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, 200, 30)];

    _twoLabel.text = @"调查2222";

    _twoLabel.font = [UIFont systemFontOfSize:15];

    [self addSubview:_twoLabel];

设置分段导航器

标签:

原文地址:http://www.cnblogs.com/bryant07/p/5388163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!