如何在 iOS 7 的 UIPickerView 中更改文本字体? [英] How can I change text font in UIPickerView in iOS 7?

查看:41
本文介绍了如何在 iOS 7 的 UIPickerView 中更改文本字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以更改字体颜色,但还需要更改字体大小,我该如何实现?这是我更改颜色的代码,

I was able to change my font color but I also need to change font size, how can I accomplish that? Here's my code for chaning the color,

 - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *title = _currencyName[row];
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

    return attString;
 }

更新:这不起作用:

 NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Light" size:40]}];

推荐答案

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel* tView = (UILabel*)view;
    if (!tView)
    {
       tView = [[UILabel alloc] init];
       [tView setFont:[UIFont fontWithName:@"Helvetica" size:14]];
       //[tView setTextAlignment:UITextAlignmentLeft];
       tView.numberOfLines=3;
    }
    // Fill the label text here
    tView.text=[wishvalues objectAtIndex:row];
   return tView;
}

这篇关于如何在 iOS 7 的 UIPickerView 中更改文本字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆