Search code examples
iphoneiosuipickertext-size

How to change the size of the characters inside a UIPicker


I am trying to center and change the size of the text inside my UIPicker but am not sure how... I think it might happen in one of these methods, most likely the first...

- (NSString*)pickerView:(UIPickerView*)pv titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [[NSString stringWithFormat:@"%x",row ] uppercaseString]; //Sets picker options as an Uppercase Hex value
}


#pragma mark UIPickerViewDataSource methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pv
{
    return 5; //5 columns in the picker
}

- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
    return 16;
}

Dose anyone one know how this can be done? I have looked around but the documentation is fairly thin...


Solution

  • Johns,

    As in Table Views, you can't change the font attributes of the default title that you usually set in the titleForRow delegate method, instead you have to use the following method:

    - (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component
    

    Here you can create an UIView with a custom UILabel and set the Label's font size, color and other attributes.

    This method is described in Apple's UIPickerView Class Reference

    Hope this help you!