现在的位置: 首页 > 综合 > 正文

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

2013年12月10日 ⁄ 综合 ⁄ 共 628字 ⁄ 字号 评论关闭

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

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

【上篇】
【下篇】

抱歉!评论已关闭.