将userInteractionEnabled
属性设置UILabel
为YES
修复突出显示问题,但它也禁用UIPickerView
自动滚动以选择已触摸的行。
如果要禁用突出显示行为,但要保留UIPickerView
的默认自动滚动功能,setShowSelection
请UITableCell
在UIPickerView
. 一种方法是对类进行子UILabel
类化,类似于以下内容:
PickerViewLabel.h -
#import <UIKit/UIKit.h>
@interface PickerViewLabel:UILabel
{
}
@end
PickerViewLabel.m -
#import "PickerViewLabel.h"
@implementation PickerViewLabel
- (void)didMoveToSuperview
{
if ([[self superview] respondsToSelector:@selector(setShowSelection:)])
{
[[self superview] performSelector:@selector(setShowSelection:) withObject:NO];
}
}
@end
然后,在您之前返回 in 的实例的地方UILabel
,pickerView:viewForRow:forComponent:reusingView:
返回 的实例PickerViewLabel
。例如,使用DougUILabel
中的代码,您可以用 ' '替换所有 ' ' 的情况PickerViewLabel
。只记得删除pickerRowLabel.userInteractionEnabled = YES;
线。