Pradhyuman sinh
Pradhyuman sinh

Reputation: 3928

Set font as per width

Hello friends I am displaying text in UIPickerview row. But when the label size is too big then Picker row displays ... at the end of the label.

I want to display whole title in row of Picker instead of this. Can i set the font size automatically as per the title width in pickerview.

Upvotes: 2

Views: 142

Answers (2)

Satish
Satish

Reputation: 1012

You need to implement following method:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

    UILabel* tView = (UILabel*)view;

    if (!tView){

        tView = [[UILabel alloc] init];

        // Setup label properties - frame, font, colors etc
        ...
    }

    // Fill the label text here
    ...
    return tView;
}

Upvotes: 2

HalR
HalR

Reputation: 11083

Make your controller a UIPickerViewDelegate and UIPickerViewDataSource, then you can use this routine to make any custom change you want for your picker row:

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

//make your own view here, it can be a UILabel if you want, or other kind of view.

//You can give it any size font you need.

}

Upvotes: 1

Related Questions