按鈕 button
// 初始化 類方法
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200, 40);
button.center = self.view.center;
//設(shè)置標(biāo)題
[button setTitle:@"提交" forState:UIControlStateNormal];
[button setTitle:@"button" forState:UIControlStateSelected];
//設(shè)置圓角
button.layer.cornerRadius = 10;
// 設(shè)置標(biāo)題顏色申尼。
[button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
//添加交互事件
[button addTarget:self action:@selector(action_button:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor yellowColor];
pagecontrol
- (UIPageControl *)pagecontrol{
if (_pagecontrol == nil){
_pagecontrol = [[UIPageControl alloc]initWithFrame:CGRectMake(Screen_Width * 2.3, Screen_Height * 0.6, Screen_Width * 0.4, 30)];
_pagecontrol.numberOfPages = 3;
_pagecontrol.currentPage = 0;
}
return _pagecontrol;
}
分段控制器
- (UISegmentedControl *)segmentConrol{
if (!_segmentConrol) {
_segmentConrol = [[UISegmentedControl alloc]initWithItems:@[@"白色",@"橙色",@"綠色",@"灰色"]];
_segmentConrol.frame = CGRectMake(0, 0, 300, 30);
_segmentConrol.center = CGPointMake(self.view.center.x, 40);
_segmentConrol.backgroundColor = [UIColor whiteColor];
//設(shè)置默認(rèn)選中的下標(biāo)
_segmentConrol.selectedSegmentIndex = 0;
[_segmentConrol addTarget:self action:@selector(action_swithControl:) forControlEvents:UIControlEventValueChanged];
}
return _segmentConrol;
}
滑條
- (UISlider *)slider{
if (!_slider) {
// 滑動條,顯示高度規(guī)定了的
_slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 0, 300, 30)];
_slider.center = CGPointMake(self.view.center.x, 300);
//設(shè)置當(dāng)前值
_slider.value = 1.0;
[_slider addTarget:self action:@selector(action_swithControl:) forControlEvents:UIControlEventValueChanged];
}
return _slider;
}
進(jìn)度條
- (UIProgressView *)progressview{
if (!_progressview) {
_progressview = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 0, 300, 30)];
_progressview.center = CGPointMake(self.view.center.x, 500);
//設(shè)置進(jìn)度
_progressview.progress = 1.0;
//設(shè)置進(jìn)度顏色
_progressview.progressTintColor = [UIColor redColor];
_progressview.trackTintColor = [UIColor yellowColor];
}
return _progressview;
}
活動指示器
- (UIActivityIndicatorView *)indicatorview{
if (!_indicatorview) { //不用點(diǎn)語法工碾。應(yīng)為這是getter柱锹。
// 使用樣式初始化屡久,大小已經(jīng)規(guī)定
_indicatorview = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_indicatorview.center = self.view.center;
//開啟動畫
[_indicatorview startAnimating];
// 默認(rèn)温眉,沒有動畫的時候?yàn)殡[藏惭等。
// _indicatorview.hidesWhenStopped = YES;
}
return _indicatorview;
}
開關(guān)
- (UISwitch *)switchControl{
if (!_switchControl) {
//大小也是固定了的
_switchControl = [[UISwitch alloc]init];
_switchControl.center = CGPointMake(200, 200);
_switchControl.thumbTintColor = [UIColor redColor];//按鈕顏色苫费。
_switchControl.tintColor = [UIColor orangeColor];// 主色調(diào)
//設(shè)置開關(guān)初始值
_switchControl.on = YES;
// 添加事件
[_switchControl addTarget:self action:@selector(action_swithControl:) forControlEvents:UIControlEventValueChanged];
}
return _switchControl;
}