您可以通過滑動和點擊選擇帶下方或上方的項目來滾動UIPickerView。UIPickerView點擊滾動和自定義行UIViews
您可以通過爲每行指定NSString作爲標題或可重用UIViews來填充UIPickerView。
我注意到當我從提供字符串切換到提供視圖時,點擊滾動不再有效。這是預期的行爲。我的觀點應該將某些觸摸事件轉發給UIPickerView嗎?
感謝
編輯:
下面是我實現的一個代碼示例:
// Creating the picker
screenPicker_ = [UIPickerView new];
screenPicker_.showsSelectionIndicator = YES;
screenPicker_.delegate = delegate_;
screenPicker_.dataSource = delegate_;
[self addSubview:screenPicker_];
[screenPicker_ release];
// Row view creation delegate
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
PickerRowView *pickerRowView = (PickerRowView*)view;
if(view == nil)
{
pickerRowView = [[PickerRowView alloc] initWithFrame:CGRectMake(0, 0, pickerView.frame.size.width, PICKER_ROW_HEIGHT)];
}
[pickerRowView SetTitle:@"some title"];
return pickerRowView;
}
// initailizer of the PickerRowView class (an UIView subclass)
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
CGFloat titleHeight = frame.size.height * CONTENT_TO_FRAME_RATIO;
title_ = [[UILabel alloc] initWithFrame:CGRectMake(TITLE_X, (frame.size.height - titleHeight)/2, frame.size.width, titleHeight)];
[title_ setFont:[UIFont fontWithName:@"StainlessExt-Light" size:titleHeight]];
title_.backgroundColor = [UIColor clearColor];
[self addSubview:title_];
[title_ release];
self.userInteractionEnabled = NO;
}
return self;
}
謝謝,這樣的作品,但現在點擊行簡要藍色高亮顯示... – 2010-08-30 06:36:22