Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a UIPickerView, and I would like to make the text word wrap.

Here is my code:

Objective-C
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    if (component == 0) {
    UILabel *lView = (UILabel *)view;

    if (!tView) {
        tView = [[UILabel alloc] init];
        [tView setFont:[UIFont systemFontOfSize:15]];
        tView.numberOfLines = [categorie count];
    }
    tView.text = [categorie objectAtIndex:row];
    return tView;
    }
    else {
        UILabel *lView = (UILabel *)view;

        if (!sView) {
            sView = [[UILabel alloc] init];
            [sView setFont:[UIFont systemFontOfSize:15]];
            sView.numberOfLines = [subCat count];
        }
        sView.text = [subCat objectAtIndex:row];
        return sView;
    }
}

I tried setting sView.numberOfLines = 0; (which is how you would normally set a UILabel to word wrap, or have more than 1 line) but that didn't work.
Posted

1 solution

You must also set the breakmode as described on Stackoverflow. If you want to go further this may also be interesting.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900