UIPickerView 上方的 UIButton

发布于 2024-12-27 14:52:15 字数 1198 浏览 2 评论 0原文

我有一个可以正常工作的 UIPickerView,现在我想在其上方添加一个按钮,以便我可以将其关闭。

这是我启动 UIPickerView 及其关闭按钮的代码:

- (UIPickerView *)creatPickerView {
    UIPickerView *tempPickerView = [[[UIPickerView alloc] 
    initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
    tempPickerView.showsSelectionIndicator = YES;
    tempPickerView.delegate = self;
    tempPickerView.dataSource = self;
    UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
    [pickerButton setBackgroundImage:[UIImage imageNamed:@"hidePicker.png"] 
         forState:UIControlStateNormal];
    [pickerButton addTarget:self action:@selector(hidePicker)   
         forControlEvents:UIControlEventTouchUpInside];
    [tempPickerView addSubview:pickerButton];
    [pickerButton release];

    [self.view addSubview:tempPickerView];
    return tempPickerView;
}

它在我的 iPhone 4.3 模拟器上运行良好,如下所示:

在此处输入图像描述

显然,pickerView 的右上角有一个按钮,

问题是,当我在我的设备(5.0.1 iPhone4 和 4.2.1 iTouch)中运行该应用程序时,该按钮是错过了,就像它从未被添加到 pickerView 中一样。

谁能帮我解决这个问题吗?

非常非常感谢!

I have a UIPickerView which works correctly, now I want to add a button above it so that I can dismiss it.

and here is my code where I initiate a UIPickerView as well as its dismiss button:

- (UIPickerView *)creatPickerView {
    UIPickerView *tempPickerView = [[[UIPickerView alloc] 
    initWithFrame:CGRectMake(kPickerViewX, kPickerViewY, kPickerViewWidth, kPickerViewHeight)] autorelease];
    tempPickerView.showsSelectionIndicator = YES;
    tempPickerView.delegate = self;
    tempPickerView.dataSource = self;
    UIButton *pickerButton = [[UIButton alloc] initWithFrame:CGRectMake(270, -32, 50, 32)];
    [pickerButton setBackgroundImage:[UIImage imageNamed:@"hidePicker.png"] 
         forState:UIControlStateNormal];
    [pickerButton addTarget:self action:@selector(hidePicker)   
         forControlEvents:UIControlEventTouchUpInside];
    [tempPickerView addSubview:pickerButton];
    [pickerButton release];

    [self.view addSubview:tempPickerView];
    return tempPickerView;
}

and it works well on my iPhone 4.3 Simulator, like this:

enter image description here

apparently there is a button on the upper right of the pickerView,

problem is, when I run the app in my device - a 5.0.1 iPhone4 and a 4.2.1 iTouch, the button is missed like it has never been added to the pickerView.

Can anyone help me with this?

Thanks a lot and a lot!

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

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

发布评论

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

评论(1

谈场末日恋爱 2025-01-03 14:52:15

我找到原因了,好像是这个png有问题,

我换了另一个png后,它就出现在屏幕上了!

但真正的问题是我将按钮放置在 pickerView 之外,这导致按钮不可触摸。

但无论如何,挑选只是一个小问题。

I found the reason, it seems the png has some problem,

after I change another png, it comes up in the screen!

but the real problem is that I place the button outside of the pickerView which results in the button's untouchableness.

But anyway the pickure is only a small problem.

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