Phi*_*Bot 24 iphone objective-c uinavigationbar ios autoresizingmask
我正在使用UINavigationBar的自定义标题视图,其代码如下:
// Set a label to the nav bar
THLabel *titleLabel = [[THLabel alloc] init];
titleLabel.text = @"Test";
titleLabel.font = [UIFont fontWithName:APP_FONT size:22.0];
titleLabel.frame = CGRectMake(0, 0, 100, 30);
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = CUSTOM_LIGHT_BLUE;
titleLabel.strokeColor = kStrokeColor;
titleLabel.strokeSize = kStrokeSize;
self.navigationItem.titleView = titleLabel;
Run Code Online (Sandbox Code Playgroud)
问题是,当呈现一个新的viewcontroller然后返回到原始视图控制器时,这个自定义视图会移动,然后重新居中.请参阅视频以了解相关信息.
请在此处观看视频:https: //www.youtube.com/watch?v = 961CCVQmpJM&feature = youroutu.be
我已经使用故事板和每个视图控制器的代码禁用了导航控制器的每个子视图的自动调整:
// Set the navigation bar hidded on the log in view
UINavigationController* mainViewController = (UINavigationController*)self.appDelegate.window.rootViewController;
[mainViewController setNavigationBarHidden:YES];
[[mainViewController navigationBar] setAutoresizesSubviews:NO];
Run Code Online (Sandbox Code Playgroud)
但它仍然调整大小!我怎么能阻止这个 - 我做错了什么?谢谢!
我会将标签嵌入到UIView. Interface Builder中不喜欢直接把一个UILabel在titleView由于某些原因,可能与你的问题。
也尝试将 设置autoResizingMask为UIViewAutoresizingFlexibleTopMargin。根据我的经验,条形图中的任何自定义视图都以这种方式表现得更好。
| 归档时间: |
|
| 查看次数: |
15399 次 |
| 最近记录: |