开发者

How to align picker view title text on each row to the right?

开发者 https://www.devze.com 2022-12-29 03:12 出处:网络
How can I align the title of each row in开发者_开发技巧 a UIPickerview to the right? Thanks in advance.You can implement delegate\'s pickerView:viewForRow:forComponent:reusingView: method and return

How can I align the title of each row in开发者_开发技巧 a UIPickerview to the right?

Thanks in advance.


You can implement delegate's pickerView:viewForRow:forComponent:reusingView: method and return UILabel instance from it:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* label = (UILabel*)view;
    if (view == nil){
       label= [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];

       label.textAlignment = UITextAlignmentRight;
       //Set other properties if you need like font, text color etc
       ...
    }
    label.text = [self textForRow:row forComponent:component];
    return label;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消