在UIPickerView中选择不同的字体大小?

时间:2014-04-16 22:59:47

标签: ios uipickerview font-size

有谁知道如何在UIPickerView中设置数组的字体大小。

//Set selectedElement's font to selectedFont
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

{
ContainerViewController container = (ContainerViewController )[self navigationController].parentViewController;
UITextView selectedText = (UITextView) container.selectedElement;
if(pickerView.tag == 1) {
UIFont selectedFont = [UIFont fontWithName:[availableFonts objectAtIndex:row] size:DEFAULT_FONTSIZE];
[selectedText setFont:selectedFont];
} else {
NSNumber selectedFontSize = [availableFontSizes objectAtIndex:row]

    //Set selectedText's font size to selectectedFontSize


}
}

1 个答案:

答案 0 :(得分:1)

试试这个:

UIFont *font1 = [UIFont fontNamesForFamilyName:@"Helvetica"];
UIFont *font2 = [UIFont fontNamesForFamilyName:@"HelveticaNeue-Bold"];
UIFont *font3 = [UIFont fontNamesForFamilyName:@"Helvetica Neue"];

self.availableFonts =  [NSArray arrayWithObjects:font1, font2, font3, nil];


//Set selectedElement's font to selectedFont
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

{
ContainerViewController container = (ContainerViewController )[self navigationController].parentViewController;
UITextView selectedText = (UITextView) container.selectedElement;
if(pickerView.tag == 1) {
UIFont selectedFont = [availableFonts objectAtIndex:row];
[selectedText setFont:selectedFont];
} else {
NSNumber selectedFontSize = [availableFontSizes objectAtIndex:row]

    //Set selectedText's font size to selectectedFontSize


}
}