访问uiviews的子视图可以吗

发布于 2024-11-07 23:13:28 字数 579 浏览 0 评论 0原文

我看到了许多聪明的想法,可以将视图和控件调整为我们想要的样子,其中一些在 SO 上列出:

  1. 透明 UISearchBar​​iPad/iPhone uiSearchbar 透明背景
  2. 不同颜色的UISegmentedControlUISegmentedControl 选定的段颜色

我想知道,这合法吗?每当有人对诸如 [[view subviews] objectAtIndex:0] 之类的东西进行硬编码时,似乎就涉及到一些黑客行为,但似乎到处都是这样做的……有人可以对此发表评论,也许可以给出一些建议吗?观点?按照规则书可以吗?有没有人发布过这样的生产代码并且被苹果接受了?

I have seen many bright ideas to massage views and controls into looking exactly the way we want them, some of them listed here on SO:

  1. Transparent UISearchBar: iPad/iPhone uiSearchbar transparent background
  2. Different colored UISegmentedControl: UISegmentedControl selected segment color

I was wondering, is this legal? There seems to be some element of hackery involved whenever someone hardcodes something like [[view subviews] objectAtIndex:0], but it seems to be done everywhere...can someone comment on this and perhaps give some perspectives? Is it ok by the rule books? Has anyone released production code like this and has it been accepted by apple?

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

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

发布评论

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

评论(3

夜司空 2024-11-14 23:13:28

它作为 API 的一部分公开,因此是合法的。我已经在 App Store 中当前的一个应用程序上完成了此操作,而且我知道其他人也做了同样的事情。

It's exposed as part of the API, therefore it's legal. Ive done it on an application currently in the App Store, and I know others have done the same.

清音悠歌 2024-11-14 23:13:28

几乎所有好看的应用程序都做到了这一点并且得到了很好的批准。当您决定这样做时,请做好迎接新版本 iOS 的准备,该版本可能会破坏您正在做的事情,并准备好立即发布更新

Just about every good looking app has done this and been approved just fine. When you make the decision to do so, just be prepared for a new version of iOS that may break what you are doing and be ready to release an update immediately

舂唻埖巳落 2024-11-14 23:13:28

仅仅因为您能够做某事,并不意味着它在所有地方都适合。在某些情况下,访问视图的子视图的能力是必要的,但是对于您不维护的组件,我会担心依赖位于层次结构中特定位置的特定 UIView。无法保证特定子视图在 sdk 的未来版本中始终是第 0 个子视图。

如果这是唯一的方法,那么您可能没有其他选择,但请记住,它是应用程序的脆弱部分,应该针对所有平台上的每个 sdk 版本进行良好的测试。

Just because you are able to do something, doesn't mean it's appropriate in all places. The abilitiy to access the subviews of a view is necessary in some situations, however I would be apprehensive about relying on a particular UIView being at a specific position in the hierarchy for components that you do not maintain. There is no guarantee that a specific subview will always be the zeroth subview in future versions of the sdk.

If this is the only way to do it then you may not have another choice, but remember that it is a fragile part of your app and should be well tested for every sdk release on all platforms.

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