定制外观和;感觉UIPickerView;

时间:2012-04-18 07:26:06

标签: iphone uipickerview uipickerviewcontroller

我想在以下设计中使用UIPickerView;

http://dl.dropbox.com/u/53051470/Screen%20shot%202012-04-18%20at%2012.02.36%20PM.png (抱歉为新用户,无法在此处粘贴图片)

我也阅读了同一主题的其他问题,并尝试实施 pickerView:viewForRow:forComponent:reusingView: 方法,但是没有得到实际的结果;

要求如选中的值应显示在带有复选标记图像的绿色条中,并以白色显示;此外,当用户开始滚动拾取器时,进入绿色条内的任何值都应变为绿色,任何离开绿色条的值都应变为黑色;

有什么建议吗?

亲切的问候;

2 个答案:

答案 0 :(得分:0)

你应该使用方法

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

并确定哪一行是突出显示

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{   
        // i use a UILabel instead of your **custom UIView** , you may add a tick in you custom view

        UILabel *testRow = view?(UILabel *)view:[[[UILabel alloc] initWithFrame:CGRectMake(0,0, 140, 40)] autorelease];
        testRow.font = [UIFont fontWithName:[testArray objectAtIndex:row] size:16];
        testRow.text = [fontsArray objectAtIndex:row];
        testRow.backgroundColor = [UIColor clearColor];

        if ( row == selectedRow )
        {
            testRow.backgroundColor = [UIColor greenColor];
        }

        return testRow;
}

不要忘记将showsSelectionIndicator设置为NO

pickView.showsSelectionIndicator = NO;

答案 1 :(得分:0)

UIPickerView多选行为,无需在选择器视图前添加其他视图,使用:https://github.com/alexleutgoeb/ALPickerView

非常感谢改进!