0

In viewDidLoad I'm setting the height to be different from the standard 44 points. I want it to be 35 points, for example. Using the code:

CGRect frame = [[UIScreen mainScreen] bounds];
[self.navigationController.toolbar setFrame:CGRectMake(0, frame.size.height-35.f, frame.size.width, 35.f)];

and checking the frame's dimensions before and after I get a printout of:

Before: {{0, 623}, {375, 44}}
After:  {{0, 632}, {375, 35}}

However when checking for this in the simulator, the height is constantly 44 points. The same is true when I use a large height value like 350, I get:

Before: {{0, 623}, {375, 44}}
After:  {{0, 317}, {375, 350}}

I have thought of subclassing UIToolbar and creating my own but UIToolbar on UINavigationController is a readonly property. What else may I try?

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
Alex Smith
  • 468
  • 5
  • 22
  • Have you tried setting it's frame in `viewWillAppear:` ? – n00bProgrammer Nov 04 '14 at 05:47
  • Yes. Though, `viewWillAppear:` is actually called after `viewDidLoad` so I don't think this is necessary even if it did allow it to work. – Alex Smith Nov 04 '14 at 05:51
  • 1
    Overriding `layoutSubviews` in a subclass seems the best bet to me. I tried with many possible solutions, but adding an `@implementation` block for `UIToolBar` and overriding `layoutSubviews` is the only working solution I have found, yet. – n00bProgrammer Nov 04 '14 at 06:08
  • This is possible even if UIToolbar on UINavigationController is a readonly property? – Alex Smith Nov 04 '14 at 06:16
  • 1
    Thanks, @n00bProgrammer! Creating a category on UIToolbar and overriding said method `layoutSubviews` did the trick! Thank you very much! – Alex Smith Nov 04 '14 at 06:25
  • Glad I could help. Even I learned something new today, thanks to you. :) – n00bProgrammer Nov 04 '14 at 06:30
  • It doesn't come without its own pitfalls, however. I'm now stuck with placing any UIBarButtonItems individually which is not fun. :/ – Alex Smith Nov 04 '14 at 06:43
  • Luckily for me, I'm just treating this toolbar as just another view anyway. It's hardly FOR UIBarButtonItems. – Alex Smith Nov 04 '14 at 07:01

1 Answers1

-1

Please try the steps below,

  1. Subclass the UIToolbar
  2. Override the DrawRect
  3. specify the new behaviour of the toolbar

Hope this may help you.

Andy
  • 49,085
  • 60
  • 166
  • 233
Neenu
  • 6,848
  • 2
  • 28
  • 54
  • While subclassing would be nice, I can't assign my subclass of `UIToolbar` to a readonly property (which is the case on `UINavigationController`). If you can think of a way around this, that would be helpful. My goal is to have my Toolbar persist between view controllers without having it's content/context change. – Alex Smith Nov 04 '14 at 06:44