I use a button as the titleView. But when I want to get the height of the button, whennever I use the self.button.frame.size.height or self.navigationItem.titleView.frame.size.height, it always return 0; Other value (like x, y and width) may seems reasonable.
Why?
In loadView
{
self.switchButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.switchButton setTitle:@"TapMe" forState:UIControlStateNormal];
self.navigationItem.titleView = self.switchButton;
[self.switchButton addTarget:self action:@selector(doSomeThing:) forControlEvents:UIControlEventTouchUpInside];
}
And
-(void)doSomeThing:(id)sender
{
NSLog(@"height%f", self.switchButton.frame.size.height);
}
You can use
First assign A view to TitleView
Then to find the height of titleView
and please keep this in mind that if any view is not assigned to titleView of the NavigationItem It will return you 0.000;