0

I know how to make a navigationController's navigationBar hidden:

@implementation UINavigationBar (custom)
    - (void)drawRect:(CGRect)rect {}
@end

However, when displaying a UIImagePickerController it also applied to it.

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.navigationBar.tintColor = [UIColor blackColor];
picker.navigationBar.barStyle = UIBarStyleBlackOpaque; // Or whatever style.
[self presentModalViewController:picker animated:NO];

Is there a way to only make some of the navigationController's navigationBar transparent?

Thanks.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
iosfreak
  • 5,228
  • 11
  • 59
  • 102

1 Answers1

0

If you need -drawRect: to behave differently for different instances of UINavigationBar, you could use something like objc_setAssociatedObject to record some indicator of whether it should be transparent. Then in -drawRect: you can use objc_getAssociatedObject on self to find out what to do.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • That will hide the whole bar. I just want to make the background transparent (which is what that code does)... – iosfreak Aug 09 '11 at 17:25
  • You can set or clear this property in your view controllers' `-viewDidAppear` or `-viewDidDisappear` methods. – Chaitanya Gupta Aug 09 '11 at 17:29
  • @jkbandes: can you give me a example of objc_setAssociatedObject? I have never worked with it before. – iosfreak Aug 09 '11 at 17:34
  • @Chaitanya Gupta I think I tried that before, but it didn't work. You have to have the drawRect for it to appear clear... – iosfreak Aug 09 '11 at 17:34
  • @phpnerd211: [this question and its answer](http://stackoverflow.com/questions/2846218/how-do-i-use-objc-setassociatedobject-objc-getassociatedobject-inside-an-object) have some good information. – jtbandes Aug 09 '11 at 17:36
  • @jtbandes: I am so confused. How would I tell if it is a UIImagePickerController in the `drawRect:`? The link you provided confused me even more..Thanks! – iosfreak Aug 10 '11 at 14:21
  • You would probably want to to use `objc_setAssociatedObject` when you create it. Then in `drawRect:` you just check if the value is set. – jtbandes Aug 10 '11 at 19:06
  • @jtbandes: I've done some searching and I still can't figure it out! How in the world would you call the `objc_setAssociatedObject` when creating the UIImagePicker? How woud you read it? Thanks! – iosfreak Aug 11 '11 at 15:30