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);
}