本文介绍了UIPickerView:NSAttributedString在iOS 7中不可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎UIPickerView不再支持将NSAttributedString用于选择器视图项。谁能证实这一点?我在 UIPickerView.h 文件中找到 NS_AVAILABLE_IOS(6_0),但这是问题吗?有没有解决方法,或者我运气不好?

It seems the UIPickerView no longer supports the use of NSAttributedString for picker view items. Can anyone confirm this? I found NS_AVAILABLE_IOS(6_0) in the UIPickerView.h file, but is this the problem? Is there a way around this, or am I out of luck?

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0); // attributed title is favored if both methods are implemented
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;


推荐答案

这个问题的唯一解决办法显然是使用 pickerView:viewForRow:forComponent:reusingView:并返回带有属性文本的UILabel,因为Apple显然已使用属性字符串禁用了。

The only solution to this problem is apparently to use pickerView:viewForRow:forComponent:reusingView: and return a UILabel with the attributed text, since Apple has apparently disabled using attributed strings otherwise.

这篇关于UIPickerView:NSAttributedString在iOS 7中不可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:18