0

I maintain an application for iOS. In the app, I use this library:

https://github.com/alfonsotesauro/FittedSheets?organization=alfonsotesauro&organization=alfonsotesauro

I have an issue of a Navigation Controller titlebar displaying as transparent since the last beta releases of iOS 15. I have succeeded in live fixing the issue using the Xcode "Capture View Hierarchy" issue and manually execute setBackgroundcolor with the UIView as the receiver, but I don't succeed to make the modification persistent because I don't succeed to get a reference to that particular UIView because of the cumbersome nature of the library and my lack of iOS programming skills. Any possible magic to reach an arbitrary subview in a complex UIView/UIViewController hierarchy ? I would imagine something like this:

func traverseSubviewsAndControllersHierarchy(_ view: UIView) -> String {

    var tag: Int = 0
    
    return ""

}

Thanks a lot for your interest.

Alfonso Tesauro
  • 1,730
  • 13
  • 21
  • You can definitely do a recursive search of the `UIView`s and their subviews, but I'm a little confused by your example. Can you explain what the tag and the empty String are meant to represent in this case? – jnpdx Oct 31 '21 at 20:23
  • Thanks a lot jnpdx for your help. Given that I can reference the particular UIView using its raw memory address using the Capture View Hierarchy, I was thinking of setting a tag like 666 and use it to tell it apart from other views. Something like a mixture of raw lldb approach and hard coded utility method. The return string would return the hierarchy I should finally use to reference the particular UIView From the source code and make my simple backgroundColor modification persistent. Thanks again jnpdx – Alfonso Tesauro Oct 31 '21 at 20:35
  • Before going down that rabbit hole, do you know about `UIAppearance` and using it to set global appearance properties of certain types of UI elements? – jnpdx Oct 31 '21 at 20:39
  • Thousand thanks jnpdx I will try to learn that topic as soon as I can – Alfonso Tesauro Oct 31 '21 at 21:36
  • You can also search for `UIView recursive subviews` and find some good answers about how to find a view ([this](https://stackoverflow.com/questions/32301336/swift-recursively-cycle-through-all-subviews-to-find-a-specific-class-and-appen) for example). I recommend that you probably don't use your idea about using a `String` to represent the view hierarchy though -- if you *do* need to use the recursive route, just find the view and set the property -- don't worry about storing the path to it. – jnpdx Oct 31 '21 at 21:38
  • Thanks a lot jnpdx, while I experiment around your precious suggestions, I send you a link (https://github.com/alfonsotesauro/stackoverflowfittedsheetsviewhierarchy) to a public repository I created containing a PDF file showing the UIView/UIViewController/UINavigationController hierarchy. Of course the view I am interested in is the last one. Perhaps you can guess better my problems. The main problem is that I am rather a macOS desktop developer. Again, thousands thanks for your outstanding help. – Alfonso Tesauro Oct 31 '21 at 21:53
  • Can you give the view you want to change with a unique `tag` value in Interface Builder then locate it with `viewWithTag(_ tag: Int)`? It seems really obvious, but I'm not sure precisely what you are asking. – Scott Thompson Nov 01 '21 at 02:25

0 Answers0