Search code examples
iphoneuipickerview

right align text in UIPickerView


How can I right align text in a UIPickerView? I tried to make custom UILabels for the row views, but for some reason, nothing is showing up, right-aligned or otherwise. Here's what I wrote:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    [label setText:[NSString stringWithFormat:@"row %d", row]];
    [label setTextAlignment:UITextAlignmentRight];
    return [label autorelease];
}

In case anyone is wondering, I used CGRectZero because I saw it in the UICatalog example.


Solution

  • Your not seeing anything because of CGRectZero. You need to set a size in your case.

    In the UICatalog, if your talking about how they used CGRectZero for the CustomView... well if you look at CustomView.m you will see they are actually disregarding the CGRectZero and setting a frame to a size in the initWithFrame: