基本控件

按钮 button

// 初始化 类方法
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 200, 40);
    button.center = self.view.center;
    //设置标题
    [button setTitle:@"提交" forState:UIControlStateNormal];
    [button setTitle:@"button" forState:UIControlStateSelected];
    //设置圆角
    button.layer.cornerRadius = 10;
    // 设置标题颜色。
    [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];
        //设置默认选中的下标
        _segmentConrol.selectedSegmentIndex = 0;
        [_segmentConrol addTarget:self action:@selector(action_swithControl:) forControlEvents:UIControlEventValueChanged];
    }
    return _segmentConrol;
}

滑条

- (UISlider *)slider{
    if (!_slider) {
        // 滑动条,显示高度规定了的
        _slider = [[UISlider alloc]initWithFrame:CGRectMake(0, 0, 300, 30)];
        _slider.center = CGPointMake(self.view.center.x, 300);
        //设置当前值
        _slider.value = 1.0;
        [_slider addTarget:self action:@selector(action_swithControl:) forControlEvents:UIControlEventValueChanged];
    }
    return _slider;
}

进度条

- (UIProgressView *)progressview{
    if (!_progressview) {
        _progressview = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 0, 300, 30)];
        _progressview.center = CGPointMake(self.view.center.x, 500);
        //设置进度
        _progressview.progress = 1.0;
        //设置进度颜色
        _progressview.progressTintColor = [UIColor redColor];
        _progressview.trackTintColor = [UIColor yellowColor];
    }
    return _progressview;
}

活动指示器

- (UIActivityIndicatorView *)indicatorview{
    if (!_indicatorview) { //不用点语法。应为这是getter。
        // 使用样式初始化,大小已经规定
        _indicatorview = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        _indicatorview.center = self.view.center;
        //开启动画
        [_indicatorview startAnimating];
        // 默认,没有动画的时候为隐藏。
//        _indicatorview.hidesWhenStopped = YES;
    }
    return _indicatorview;
}

开关

- (UISwitch *)switchControl{
    if (!_switchControl) {
        //大小也是固定了的
        _switchControl = [[UISwitch alloc]init];
        _switchControl.center = CGPointMake(200, 200);
        _switchControl.thumbTintColor = [UIColor redColor];//按钮颜色。
        _switchControl.tintColor = [UIColor orangeColor];// 主色调
        //设置开关初始值
        _switchControl.on = YES;
        // 添加事件
        [_switchControl addTarget:self action:@selector(action_swithControl:) forControlEvents:UIControlEventValueChanged];
    }
    return _switchControl;
}

你可能感兴趣的:(基本控件)