UIPickerView内容居中显示,设置初始默认值

来源:互联网 发布:数据精灵后台授权 编辑:程序博客网 时间:2024/03/28 22:40

系统默认的是内容居左显示的,有时会觉得不太好看,可以实现代理方法。

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

{
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(12.0f, 0.0f, [pickerView rowSizeForComponent:component].width-12, [pickerView rowSizeForComponent:component].height)] autorelease];

    [label setText:[pickerData objectAtIndex:row]];

    label.backgroundColor = [UIColor clearColor];
    [label setTextAlignment:UITextAlignmentCenter];
    return label;
}

设置初始默认值

[pickerView selectRow:3 inComponent:0 animated:NO];


转自:http://blog.csdn.net/xiaoxiangzhu660810/article/details/9271239

0 0
原创粉丝点击