//-----------------------------------------------------------------UIButton----------------------------------------------------------

    CGRect rect = CGRectMake(0, 100, 200, 50);

    UIButton *button = [[UIButton alloc]initWithFrame:rect];

    button.backgroundColor = [UIColor yellowColor];

    [button setTitle:@"START" forState:UIControlStateNormal];//正常状态下title

    [button setTitle:@"RESET" forState:UIControlStateSelected];//选中状态下title

    button.titleLabel.font = [UIFont systemFontOfSize:25.f];//文本框字体大小

    [button.layer setCornerRadius:10.f];      //边框圆角弧度

    [button.layer setBorderWidth:3];       //边框宽度

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });

    [button.layer setBorderColor:colorref];         //边框颜色

    [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];

   //[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];//定义事件

    [self.view addSubview:button];

    

 

    

//---------------------------------------UITextField--------------------------------------------------------------------------

    

    

    _textField = [[UITextField alloc]initWithFrame:CGRectMake(0,VIEW_BOTTOM(button)+10,ScreenRect.size.width, VIEW_HEIGHT(button))];

    _secretField = [[UITextField alloc]initWithFrame:CGRectMake(0, VIEW_BOTTOM(_textField), ScreenRect.size.width, VIEW_HEIGHT(_textField))];

    _secretField.borderStyle = UITextBorderStyleLine;

    _textField.borderStyle = UITextBorderStyleLine//边框类型

    _secretField.backgroundColor = [UIColor whiteColor];

    _textField.backgroundColor = [UIColor whiteColor];//背景颜色

    //    [textField.layer setCornerRadius:13.f];     //边框圆角幅度

    //    [textField.layer setBorderWidth:2];   //边框宽度

    //    [textField.layer setBorderColor:colorref];      //边框颜色

    _textField.placeholder = @"电话号码";       //提示文字

    _secretField.placeholder = @"密码";

    // textField.keyboardType = UIKeyboardTypeNamePhonePad;    //拨号键盘

    _textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;   //数字符号键盘;

    _secretField.keyboardType = UIKeyboardTypeASCIICapable;    //英文字母键盘

    _secretField.clearButtonMode = UITextFieldViewModeWhileEditing;

    _textField.clearButtonMode = UITextFieldViewModeWhileEditing;   //清除按钮模式

    _secretField.returnKeyType = UIReturnKeyDone;

    _textField.returnKeyType = UIReturnKeyDone;   //右下角return键行为

    _secretField.returnKeyType = UIReturnKeyDone;

    _secretField.delegate = self;                //使用代理通过return键关闭键盘

    _textField.delegate = self;                  //设置代理

    _secretField.secureTextEntry = YES;          //密码保护模式

    [self.view addSubview:_secretField];

    [self.view addSubview:_textField];

    

    

    

//    //---------------------------------------UITextView--------------------------------------------------------------------------

    _textView = [[UITextView alloc]initWithFrame:CGRectMake(0, VIEW_BOTTOM(_secretField)+10, ScreenRect.size.width, 100)];

    _textView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:_textView];

    [_textView setText:@"每个人都只能陪我们一段路,迟早是要分开的。电影中的父亲,戏份不多,言语也少,典型的中式父亲形象。火车上涛儿告诉父亲自己谈朋友了,父亲淡淡的说了一句你自己的事情你自己决定然后起身去打水,却并不打水,只是看着窗外,神情落寞。我想到了自己的父亲,想到了母亲说的话,以后你出嫁的时候,你爸肯定会哭的。最后父亲在异地的候车室独自瞑目而逝,涛儿从家中赶来,悲戚万分,追悔莫及。我们在追求虚妄浮华的现代快节奏生活的时候,往往将原本应该珍重的事情抛诸脑后,实在是不该。至亲、至爱,你所在乎的和在乎你的人正在悄然离你而去,所有的红尘往事、故人终将掩埋在时间的洪流中。"];

    _textView.textColor = [UIColor blackColor];

    _textView.layer.cornerRadius = 10.f;

    _textView.showsVerticalScrollIndicator = YES;

    _textView.showsHorizontalScrollIndicator = YES;

    _textView.bouncesZoom = YES;

    _textView.editable = YES;

    _textView.selectable = YES;

    _textView.delegate = self;

    //给文本添加导航栏,通过导航栏done键退出键盘

    _navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 44)];

    [self.view addSubview:_navBar];

    _navItem = [[UINavigationItem alloc]initWithTitle:@"导航条"];

    _navBar.items = @[_navItem ];

    

    

    _done = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(finishEdit)];

    

    

    //---------------------------------------UISwitch--------------------------------------------------------------------------

    

    _switchOfScreen = [[UISwitch alloc]initWithFrame:CGRectMake(0, VIEW_BOTTOM(_navBar), 30, 30)];

    

    //可调与动画效果

    [_switchOfScreen setOn:YES animated:YES];

    [self.view addSubview:_switchOfScreen];

    [_switchOfScreen addTarget:self action:@selector(openLight:) forControlEvents:UIControlEventTouchUpInside];

    

    

    //---------------------------------------UISegmentedControl--------------------------------------------------------------------------

    _arry = [[NSArray alloc]init];

    _arry = @[@"",@"",@""];

    _segment = [[UISegmentedControl alloc]initWithItems:_arry];

    _segment.frame = CGRectMake(0, VIEW_BOTTOM(_textView)+10, 300, 30);

    _segment.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:_segment];

    [_segment setTitle:@"世纪" forSegmentAtIndex:0];

    [_segment insertSegmentWithTitle:@"hour" atIndex:0 animated:YES];

    //_segment.momentary = YES;       //点击时显示高亮状态

    //[_segment removeSegmentAtIndex:1 animated:YES];

    [_segment isEnabledForSegmentAtIndex:1];

//    [UIView beginAnimations:nil context:nil];

//    [UIView setAnimationDuration:3];

//    _segment.center = self.view.center;

//    [UIView commitAnimations];

    //通过各种状态改变背景颜色

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

    

    

    _textOfSeg = [[UITextField alloc]initWithFrame:CGRectMake(30, VIEW_BOTTOM(_segment)+20, 100, 30)];

    _textOfSeg.backgroundColor = [UIColor whiteColor];//背景颜色

    [self.view addSubview:_textOfSeg];

    //_textOfSeg.borderStyle = UITextBorderStyleLine;  //边框类型

    [_textOfSeg.layer setCornerRadius:0.f];     //边框圆角幅度

    _textOfSeg.font = [UIFont systemFontOfSize:11]; //字体大小

    _textOfSeg.placeholder = @"输入要创建的名称";

    _textOfSeg.keyboardType = UIKeyboardTypeASCIICapable;    //英文字母键盘

    _textOfSeg.returnKeyType = UIReturnKeyDone;

    _textOfSeg.delegate = self;                //使用代理通过return键关闭键盘

    _textOfSeg.delegate = self;                  //设置代理

    

    

    

    _buttonOfAdd = [[UIButton alloc]initWithFrame:CGRectMake(VIEW_RIGHT(_textOfSeg)+20, VIEW_Y(_textOfSeg)+5, 40, 20)];

    [self.view addSubview:_buttonOfAdd];

    _buttonOfAdd.backgroundColor = [UIColor grayColor];

    [_buttonOfAdd setTitle:@"添加" forState:UIControlStateNormal];

    //添加button事件,添加分段

    [_buttonOfAdd addTarget:self action:@selector(addSeg:) forControlEvents:UIControlEventTouchUpInside];

    

    _buttonOfSub = [[UIButton alloc]initWithFrame:CGRectMake(VIEW_RIGHT(_buttonOfAdd)+10, VIEW_Y(_buttonOfAdd), 40, 20)];

    [self.view addSubview:_buttonOfSub];

    _buttonOfSub.backgroundColor = [UIColor grayColor];

    [_buttonOfSub setTitle:@"删除" forState:UIControlStateNormal];

    //添加button事件,删除最后一个分段

    [_buttonOfSub addTarget:self action:@selector(deleteSeg:) forControlEvents:UIControlEventTouchUpInside];

    

    各种方法

- (void)deleteSeg:(UIButton*)sender{

    

    NSUInteger count = _segment.numberOfSegments;

    [_segment removeSegmentAtIndex:count - 1 animated:YES];

    

}

 

- (void) addSeg:(UIButton*)sender{

    

    NSUInteger count = _segment.numberOfSegments;

    NSString *title = _textOfSeg.text;

    if ([title length] > 0) {

        [_segment insertSegmentWithTitle:title atIndex:count animated:YES];

        title = @" ";

        

    }

    

}

 

 

 

- (void)changColorOfBackGround:(UISegmentedControl*)sender{

    

    switch ([sender selectedSegmentIndex]) {

        case 0:

            self.view.backgroundColor = [UIColor yellowColor];

            break;

        case 1:

            self.view.backgroundColor = [UIColor cyanColor];

            break;

        case 2:

            self.view.backgroundColor = [UIColor redColor];

            break;

        default:

            self.view.backgroundColor = [UIColor magentaColor];

            break;

    }

    

    

}

 

 

 

 

- (void)openLight:(UISwitch*)sender{

    if (sender.isOn) {

        self.view.backgroundColor = [UIColor redColor];

        [self.view bringSubviewToFront:_switchOfScreen];

        

    }else{

        self.view.backgroundColor = [UIColor grayColor];

    }

}

 

- (void)textViewDidBeginEditing:(UITextView *)sender{

    _navItem.rightBarButtonItem = _done;

}

 

- (void)textViewDidEndEditing:(UITextView *)textView{

    _navItem.rightBarButtonItem = nil;

}

 

- (void)finishEdit{

    [self->_textView resignFirstResponder];

    

}

 

- (BOOL)textFieldShouldReturn:(UITextField *)sender{

    [sender resignFirstResponder];

    return YES;

}

 

- (void)textFieldDidEndEditing:(UITextField *)sender{

    [sender resignFirstResponder];

    

}