objective-c - UIPickerView 不改变字体 iOS 9.1

标签 objective-c uipickerview

我尝试使用此代码行更改标题中的字体。 我怎样才能做到这一点?

- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *title;
UIFont *font;

title = [[countriesToCitiesDic objectForKey:selectedCountryName]objectAtIndex:row];
font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18];

UIColor *textColor;

textColor = [UIColor whiteColor];

NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter;

NSDictionary *attributes = @{NSForegroundColorAttributeName : textColor,
                             NSFontAttributeName : font,
                             NSParagraphStyleAttributeName : paragraphStyle};

return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}

最佳答案

你可以试试这个:

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

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, 44)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:18];
label.text  = [[countriesToCitiesDic objectForKey:selectedCountryName]objectAtIndex:row];
return label;
}

关于objective-c - UIPickerView 不改变字体 iOS 9.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34395899/

相关文章:

iphone - JSON 数组和排序

iphone - stringByAddingPercentEscapesUsingEncoding :? 的反义词是什么?

objective-c - UICollectionView动态高度和宽度

ios - 使用 Swift iOS 使用 RS256 或 RS512 验证 JWT token

ios - DownPicker选中时如何获取Array Index Value

ios - 将从 UIPicker 中选择的值分配给 Swift 中的 UITextField(以及如何显示和隐藏它)

ios - 如何获取 UIPickerView 的文本?

ios - 插入 block 回调到 NSMutableDictionary

ios - 我们如何才能确定文件*不*存在于 iOS 中?

ios - 如何同时或单独控制两个选择器 View 内容?