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?

Community
  • 1
  • 1
Ying
  • 1,944
  • 5
  • 24
  • 38
  • 1
    If it isn't OK to access the subviews, why would Apple document and make public the `subviews` property? – BoltClock May 18 '11 at 20:08
  • I concur with BoltClock. They give you that power explicitly. It's up to you what you do with it. Apple is pretty good about drawing the line in the sand. – Jacob M. Barnard May 18 '11 at 20:14
  • i guess, but its not clear how the view's subviews are managed. maybe in the future one subview might come first and the other one later, both having the same visual appearance, so relying on a hardcoded index could possibly break? I am throwing out hypotheticals obviously... – Ying May 18 '11 at 21:04

3 Answers3

1

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.

Jano
  • 62,815
  • 21
  • 164
  • 192
0

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

Adrian Rodriguez
  • 3,232
  • 2
  • 24
  • 34
0

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.

jjwchoy
  • 1,898
  • 16
  • 20