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

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

- (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

你可能感兴趣的:(IT,移动开发,ios,ios开发,pickerView)