需要重写UIPickerView中的
1 -(UIView*)pickerView:(UIPickerView*)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
方法
示例代码如下
1 //自定义uipickerview中的文字大小 2 -(UIView*)pickerView:(UIPickerView*)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 3 { 4 UILabel *myView=nil; 5 6 myView=[[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 264, 30)]; 7 myView.textAlignment=NSTextAlignmentRight; 8 9 if (pickerView==self.SourcePicker) { 10 myView.text=[_SourcePickerArray objectAtIndex:row]; 11 12 }else{ 13 myView.text=[_RoomPickerArray objectAtIndex:row]; 14 } 15 myView.font=[UIFont systemFontOfSize:17]; 16 myView.textColor=[UIColor blackColor]; 17 myView.backgroundColor=[UIColor clearColor]; 18 return myView; 19 20 }
另外注意,ios6之前调整文本靠左或者靠右对齐的代码为
1 mylabel.textAlignment= UITextAlignmentCenter;
在ios7以上版本需要改为
1 mylabel.textAlignment=NSTextAlignmentCenter;