自定义 UIPickerView

发布于 2024-09-04 12:26:07 字数 610 浏览 4 评论 0原文

我有一个需要自定义 UIPickerView 的要求。选择器视图应如下所示:

替代文字

类似地定制了pickerView的应用程序是: http://itunes.apple.com/ us/app/convert-the-unit-calculator/id325758140?mt=8

我尝试通过重置 UIImagePicker 的属性 showsSelectionIndicator 并添加覆盖视图来删除默认的 pickerView 选择栏。但问题是,覆盖视图应该是透明的,以便其后面的轮子可见。但即使选择栏不透明,另一个应用程序也会以某种方式执行此操作。

关于如何实现这一壮举有什么想法吗?

谢谢和问候, 拉杰

I have a requirement where UIPickerView should be customized. The picker view should look something like this:

alt text

The application which has customized the pickerView similarly is:
http://itunes.apple.com/us/app/convert-the-unit-calculator/id325758140?mt=8

I have tried removing the default pickerView selection bar by resetting the property showsSelectionIndicator of UIImagePicker and adding a overlay view. But the problem is, the overlay view should be transparent so that the wheel behind it is visible. But the other application somehow does it even though the selection bar is not transparent.

Any ideas on how to achieve this feat?

Thanks and Regards,
Raj

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有心的人 2024-09-11 12:26:07

您必须从头开始编写自己的程序。 UIPickerview 不可自定义。在。全部。糟糕,但就是这样。我首先创建一个 uitableview 并在其周围分层框架,并尝试模仿 uipickerview。

You're going to have to write your own from scratch on this one. UIPickerview isn't customizable. At. All. Sucks, but that's how it is. I'd start out creating a uitableview and layering a frame around it, and trying to mimic uipickerview.

守护在此方 2024-09-11 12:26:07

我认为你可以打印选择器下的子视图并修改它们。
UIPickerView 在数据首次加载后创建子视图。
使用performSelecter:WithObject:afterDelay:,您可以删除它们或插入您需要的任何内容。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self refreshClock];
    [timePicker_ performSelector:@selector(leakSelf) withObject:nil afterDelay:0];
    [self performSelector:@selector(setupTimePicker) withObject:nil afterDelay:0];
}
- (void)setupTimePicker {
    [[timePicker_ subviewOfClass:NSClassFromString(@"_UIPickerViewTopFrame")] removeFromSuperview];
    CGRect frame = timePicker_.frame;
    frame.size.width += 20;
    frame.origin.x -= 10;
    timePicker_.frame = frame;
}


@implementation UIView(UIViewDebugTool)


- (void)leakSubview:(UIView*)subroot atDepth:(NSUInteger)dep {

    DLog( @"trace sub view[%u] %@", dep, [subroot description] );
    CALayer* layer = subroot.layer;
    for( CALayer* l in layer.sublayers ) {
        DLog( @"layer[%u] %@", dep, l );
    }
    for( UIView* v in subroot.subviews ) {
        [self leakSubview:v atDepth:dep+1];
    }

}

- (void)leakSelf {
    NSUInteger dep = 0;
    [self leakSubview: self atDepth:dep];
}

@end

I think you can print the subviews under the picker and modify them.
The UIPickerView create subviews after the data is first loaded.
With performSelecter:WithObject:afterDelay:, you can remove them or insert whatever you need.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self refreshClock];
    [timePicker_ performSelector:@selector(leakSelf) withObject:nil afterDelay:0];
    [self performSelector:@selector(setupTimePicker) withObject:nil afterDelay:0];
}
- (void)setupTimePicker {
    [[timePicker_ subviewOfClass:NSClassFromString(@"_UIPickerViewTopFrame")] removeFromSuperview];
    CGRect frame = timePicker_.frame;
    frame.size.width += 20;
    frame.origin.x -= 10;
    timePicker_.frame = frame;
}


@implementation UIView(UIViewDebugTool)


- (void)leakSubview:(UIView*)subroot atDepth:(NSUInteger)dep {

    DLog( @"trace sub view[%u] %@", dep, [subroot description] );
    CALayer* layer = subroot.layer;
    for( CALayer* l in layer.sublayers ) {
        DLog( @"layer[%u] %@", dep, l );
    }
    for( UIView* v in subroot.subviews ) {
        [self leakSubview:v atDepth:dep+1];
    }

}

- (void)leakSelf {
    NSUInteger dep = 0;
    [self leakSubview: self atDepth:dep];
}

@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文