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

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

问题描述

我可以改变我的字体颜色,但我也需要改变字体大小,我怎么能做到这一点?这里是我的代码chaning的颜色,

pre $ NS $分配的字符串pickerView:(UIPickerView *)pickerView的归档的行数:(NSInteger)行forComponent:(NSInteger)组件{
NSString * title = _currencyName [row];
NSAttributedString * attString = [[NSAttributedString alloc] initWithString:title属性:@ {NSForegroundColorAttributeName:[UIColor whiteColor]}];

return attString;

$ / code $ / $ p

更新:这是行不通的:

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


解决方案

   - ( UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)组件reusingView:(UIView *)view 
{
UILabel * tView =(UILabel *)view;
if(!tView)
{
tView = [[UILabel alloc] init];
[tView setFont:[UIFont fontWithName:@Helveticasize:14]];
// [tView setTextAlignment:UITextAlignmentLeft];
tView.numberOfLines = 3;
}
//在这里填写标签文本
tView.text = [wishvalues objectAtIndex:row];
返回tView;
}


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;
 }

UPDATE: this didn't work:

 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天全站免登陆