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