0

I recently discovered that in > iOS5 UINavigationBar does not get its drawRect called. I want to figure out how to draw with Core Graphics in a category.

The end goal I am trying to achieve is eliminating images from my app and have everything drawn at runtime. I am also trying to make this library automatic, so that users don't have to think about using my custom classes.

Is there a way to replace a class with one of your own at runtime? like: replaceClass([UINavigationBar class], [MyCustomBar class]);

Thanks in advance.

Weston
  • 1,481
  • 1
  • 11
  • 31

2 Answers2

0

Is there a way to replace a class with one of your own at runtime?

In Objective-C this is know as class posing.

Class posing is based on the use of NSObject's poseClass method, which is now deprecated (on 64 bit platforms, including the iPhone).

Alternative approaches have been investigated; you can read about one here, but they do not seem quite to fit the bill.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • The problem with this method, is that even if I swap drawRect in UINavigationBar with my own method, drawRect is not called in iOS5 or newer. – Weston Jan 28 '13 at 16:36
0

I found the solution, Instead of messing with draw rect, I just made some methods that draw to a UIImage then set the image as the background view for the elements i am customizing. It makes my custom UI magic again.

Weston
  • 1,481
  • 1
  • 11
  • 31