How to place UILabel
in the center of navigation bar in XCode 6? Is it possible at all? I can place here, for example, UIButton
, but unable to place UILabel
. If no, what can I do then? Place a UIButton
with the appropriate text and make it non-clickable?
Thanks in advance.
Create a UIView and add UILabel
as it's subview and then set your NavigationItem
's titleView as previously created UIView.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 40)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 40)];
label.text = @"Hello";
label.textAlignment = NSTextAlignmentCenter;
[view addSubview:label];
self.navigationItem.titleView = view;
Note: Don't forget to set your own frame values to get better result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With