UIPickerView的使用

来源:互联网 发布:php财务管理系统 编辑:程序博客网 时间:2024/03/29 01:28

类似时间选择器的PickerView,可以自定义显示内容,创建方法:

#pragma mark - 视图懒加载
-(UIPickerView *)catePickerView{
    if (!_catePickerView) {
        _catePickerView = [[UIPickerView alloc] init];
        _catePickerView.delegate =self;
        _catePickerView.backgroundColor = [UIColor whiteColor];
        _catePickerView.layer.cornerRadius = 50;
        _catePickerView.clipsToBounds = YES;
    }
    return _catePickerView;
}

代理方法返回自定义视图:

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UIView *custView = [[UIView alloc] initForAutoLayout];
    if (pickerView==_catePickerView) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 10, 100, 40)];
        [custView addSubview:label];

        label.textAlignment = NSTextAlignmentCenter;
        label.text = _cateArr[row];
        label.font = [UIFont systemFontOfSize:24];
    }
    return custView;
}

0 0
原创粉丝点击