删除 UIPickerView 蓝色突出显示

发布于 2024-10-08 18:53:19 字数 2026 浏览 3 评论 0原文

一段时间以来,当您使用 pickerView:viewForRow:forComponent:reusingView: 委托时,我一直在尝试删除 UIPickerView 中的蓝色突出显示。

我确信这里很多人都曾有过这样的经历,并希望删除 UIPickerView 中那个丑陋的蓝色突出显示。

UIPickerView 有一个 UITableView - 而是一个 UIPickerTable,其中包含您的 UILabels/UIViews/UIImageViews 或其他内容的单元格躺着。 从逻辑上讲,如果它是一个表视图,那么我们可以只访问单元格和 setSelectionStyle:UITableViewCellSelectionStyleNone 对吗? 错误。

UIPickerTable 是 API 的私有类,不允许您在其中设置任何内容。

我已经设法在我的选择器中获取所有子视图

[[myPickerView subviews] objectAtIndex:someIndexValue];

所以我在 pickerView:didSelectRow:pickerView:viewForRow: 中尝试了

NSIndexPath *path = [[[myPickerView subviews] objectAtIndex:5] indexPathForSelectedRow];
[[[[myPickerView subviews] objectAtIndex:5] cellForRowAtIndexPath:path] setSelectionStyle:UITableViewCellSelectionStyleNone];

这个:

[[[myPickerView subviews] objectAtIndex:5] setSelectionStyle:UITableViewCellSelectionStyleNone];

它们都不起作用,因为它是私人的。给我这个错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用,原因:“-[UIPickerTable setSelectionStyle:]:无法识别的选择器发送到实例 0x64479a0”

我知道如何设置 视图 的框架调整为 pickerView:rowHeightForComponent: 的大小,然后执行:

label.UserInteractionEnabled = YES;

pickerView:viewForRow 方法返回它之前。

但它并没有真正删除突出显示,它只是覆盖它并删除 UIPickerView 在单击某些项目时自动滚动的能力。

有人知道如何从内部有 UILabel/UIView/UIImageViewUIPickerView 中删除这个蓝色突出显示吗?

谈论selectionIndicator。 这是当您单击 pickerView 内的图像时出现的突出显示:

alt text

PS:此 pickerView 没有 SelectionIndicator 并且是定制的。然而,定制与这个问题无关。这个问题只是因为在选择器单元格内有一个继承 UIView 形式的对象,并且正在使用 viewForRow

For some time now I've been trying to remove the blue highlight in UIPickerView when you're using the pickerView:viewForRow:forComponent:reusingView: delegate.

I'm sure many here have been there and wanted to remove that ugly blue highlight in the UIPickerView.

The UIPickerView has a UITableView - rather a UIPickerTable inside which has cells where your UILabels/UIViews/UIImageViews or whatever lay.
Logically, if it's a tableview, then we can just access the cell and setSelectionStyle:UITableViewCellSelectionStyleNone right?
Wrong.

UIPickerTable is a private class of the API and does not allow you to set anything in there.

I've managed to get all the subviews in my picker

[[myPickerView subviews] objectAtIndex:someIndexValue];

So I tried this in pickerView:didSelectRow: and pickerView:viewForRow:

NSIndexPath *path = [[[myPickerView subviews] objectAtIndex:5] indexPathForSelectedRow];
[[[[myPickerView subviews] objectAtIndex:5] cellForRowAtIndexPath:path] setSelectionStyle:UITableViewCellSelectionStyleNone];

And this:

[[[myPickerView subviews] objectAtIndex:5] setSelectionStyle:UITableViewCellSelectionStyleNone];

None of them worked 'cause it's private. Giving me this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPickerTable setSelectionStyle:]: unrecognized selector sent to instance 0x64479a0'

I know about setting the view's frame to the size of the pickerView:rowHeightForComponent: and then doing:

label.UserInteractionEnabled = YES;

Before returning it on pickerView:viewForRow method.

But it doesn't really remove the highlight, it just covers it and removes the UIPickerView's ability to autoscroll when some item is just clicked.

Does anyone know how can I remove this blue highlight from an UIPickerView with an UILabel/UIView/UIImageView inside?

I'm NOT talking about the selectionIndicator.
This is the highlight that appears when you click an image inside the pickerView:

alt text

PS: This pickerView has NO selectionIndicator and is customized. However, the customization has nothing to do with the issue. This issue is simply for the fact that there's an object that inherits form UIView inside the picker's cell and viewForRow is being used.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文