24

I am creating a custom UIToolbar to use as a UIView in the UINavigationBar.navigationitem.titleView property. I would like to size the toolbar height to that of the .navigationitem by obtaining the current height of the .navigationitem rather than hard code it. Is there a way to obtain the height value?

James Webster
  • 31,873
  • 11
  • 70
  • 114
ChrisP
  • 9,796
  • 21
  • 77
  • 121
  • The height of a navigation item depends on the type of navigation item you've created, but you could always base your tool bar height on the height of the navigation bar. – spstanley May 06 '11 at 01:45

1 Answers1

48

Not sure if this is what you need.

self.navigationController.navigationBar.frame.size.height

AbeEstrada
  • 1,090
  • 1
  • 13
  • 15
  • 3
    Very "clean" - typical practice of Law of Demeter! :-) It's not your fault, Apple designed it. I am just pointing out how terribly it looks... – Michal Oct 04 '13 at 12:00
  • 3
    doesn't work all the time.. sometimes the navigationBar would be of a certain heigh (in my case 44) but then it would have a (private, ie you cannot access it via UIKit's apis) subview that's larger (in my case, _UINavigationBarBackground.UIBackdropView.UIView height is 64).. – abbood Mar 24 '15 at 11:14
  • This for some reason returns 46, when the height is clearly more ( I'm guessing 64 ). Maybe it's because I didn't set constraints on this object? – Trip Mar 29 '16 at 15:25