iOS开发 -- UISegmentedControl

UISegmentedControl 是UI中的分段控件 相当于一组button点击不同的分段 进行不同界面的切换展示
在使用上 和 UI中的其他控件 没有区别 也是分四步

登陆 注册 找回密码界面code

#import "RootViewController.h"
#import "LoginView.h"
#import "PasswordBackView.h"
#import "RegistView.h"

@interface RootViewController ()
@property (nonatomic,retain)LoginView *loginView;
@property (nonatomic,retain)RegistView *registView;
@property (nonatomic,retain)PasswordBackView *passwordView;
@end
@implementation RootViewController
-(void)dealloc
{
    self.loginView = nil;
    self.registView = nil;
    self.passwordView = nil;
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //布局UISegmentedControl
    [self layoutSegmentControl];
    //布局登陆 注册 找回密码
    [self layoutViews];
}
//布局UISegmentedControl
-(void)layoutSegmentControl
{
    //1: 创建对象
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:@[@"登陆",@"注册",@"找回密码"]];
    //2 配置属性
        segment.backgroundColor = [UIColor whiteColor];
    //(1)frame center
    segment.frame = CGRectMake(0, 0, 200, 30);
    segment.center = CGPointMake(375/2, 50);
    //设置点击的颜色
 //   segment.tintColor = [UIColor cyanColor];
    //设置选中的分段
    segment.selectedSegmentIndex = 1;

    //修改分段显示的内容
    [segment setTitle:@"登陆" forSegmentAtIndex:1];
    [segment setTitle:@"注册" forSegmentAtIndex:0];

    //添加事件
    [segment addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];

    //3 添加父视图
    [self.view addSubview:segment];
    //4 释放所有权
    [segment release];
}
//布局登陆 注册 找回密码
-(void)layoutViews
{
//登陆
    self.loginView  = [[LoginView alloc]initWithFrame:CGRectMake(0, 100, 375, 568)];
    [self.view addSubview:_loginView];
    [_loginView release];

    self.registView = [[RegistView alloc]initWithFrame:CGRectMake(0, 100, 375, 568)];
    [self.view addSubview:_registView];
    [_registView release];

    self.passwordView = [[PasswordBackView alloc]initWithFrame:CGRectMake(0, 100, 375, 568)];
    [self.view addSubview:_passwordView];
    [_passwordView release];

    [self.view bringSubviewToFront:_loginView];
}
#pragma mark -- 事件处理

-(void)segmentedAction:(UISegmentedControl *)segement
{
    NSLog(@"%ld",segement.selectedSegmentIndex);

    if (segement.selectedSegmentIndex == 0) {
        //注册
        [self.view bringSubviewToFront:_registView];
    }else if (segement.selectedSegmentIndex == 1)
    {
        [self.view bringSubviewToFront:_loginView];
    }else if (segement.selectedSegmentIndex == 2)
    {
        [self.view bringSubviewToFront:_passwordView];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值