如何在iOS 7中更改UIPickerView中的文本字体? [英] How can I change text font in UIPickerView in iOS 7?
本文介绍了如何在iOS 7中更改UIPickerView中的文本字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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屋!
查看全文