How to align title bar text in each line on the right?

How can I align the title of each row in a UIPickerview on the right?

Thanks in advance.

+3
source share
1 answer

You can implement the delegate method pickerView:viewForRow:forComponent:reusingView:and return an instance of UILabel 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;
}
+7
source

Source: https://habr.com/ru/post/1743769/


All Articles