Nico
Nico

Reputation: 1838

iPhone- Set Font list in PickerView

I have to show font list in Pickerview. when i set fonts array in picker view delegate method then one of the font named “Bodoni Ornaments” text got distorted in picker view label, rest all fonts get showing properly.

Please see image:

enter image description here

I am getting font list by this code:

#pragma mark- Font Array return methods 

-(NSArray*)fontFamilyArrayReturnMethod
{
    NSLog (@"Font families: %@", [UIFont familyNames]);
    return [UIFont familyNames];
}

Picker View Delegate method code:

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

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, pickerView.frame.size.width-7, 44)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont fontWithName:[arrayContainFontFamily objectAtIndex:row] size:18];
    label.text = [NSString stringWithFormat:@"%@", [arrayContainFontFamily objectAtIndex:row]];
    return label;    
}

Why this font is not coming as text in picker view label. I need font name text instead of designed character. Any help is appreciated.

Upvotes: 0

Views: 430

Answers (1)

Kamaros
Kamaros

Reputation: 4566

Having taken a quick Google search for "Bodoni Ornaments", that's actually what the font looks like, so the behaviour is actually correct.

--EDIT-- Right now, you have the following line:

label.font = [UIFont fontWithName:[arrayContainFontFamily objectAtIndex:row] size:18];

This makes it so the font name is written using the font itself. You'll have to remove this line if you want "Bodoni Ornaments" to appear as text. However, you won't be able to preview each font anymore.

Upvotes: 1

Related Questions