22 iphone height cocoa-touch uinavigationbar ios
有人可以告诉我如何更改导航栏高度?
这是我到目前为止:
CGFloat navBarHeight = 10;
self.navigationController.navigationBar.frame.size.width = navBarHeight;
Run Code Online (Sandbox Code Playgroud)
Shi*_*ner 25
您可以基于UINavigationBar这样创建类别类
.h文件
#import UIKit/UIKit.h
@interface UINavigationBar (myNave)
- (CGSize)changeHeight:(CGSize)size;
@end
Run Code Online (Sandbox Code Playgroud)
和.m文件
#import "UINavigationBar+customNav.h"
@implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(320,100);
return newSize;
}
@end
Run Code Online (Sandbox Code Playgroud)
它非常好用.
Gil*_*lin 21
您不应该更改导航栏的高度.来自View Controller的Apple编程指南:
自定义导航栏外观
在导航界面中,导航控制器拥有其UINavigationBar对象并负责管理它.不允许更改导航栏对象或直接修改其边界,框架或Alpha值.但是,有一些允许修改的属性,包括:
●barStyle属性
●半透明属性
●tintColor属性
(摘自Apple:https: //developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html)
- 更新 - IOS 7 ---仍然只能更改可用的属性,但下面是关于如何在导航栏中实现灵活性的一个很好的教程http://www.appcoda.com/customize-navigation-status-bar -IOS 7/
我已经解决了这个问题,我创建了UINavigationController的子类.在这个MainNavigationViewController.m文件中,我重写了viewDidLayoutSubviews()方法,其中我为self.navigationBar设置了框架
sizeThatFits:不再适用于iOS11 UINavigationBar子类.Apple Engineering已经确认这项技术从未受到支持,并且iOS11更改了尺寸,因此不再需要咨询.
覆盖 - (void)viewController中的viewWillAppear方法并尝试下面的代码,
- (void)viewWillAppear {
UINavigationBar *navigationBar = [[self navigationController] navigationBar];
CGRect frame = [navigationBar frame];
frame.size.height = 82.0f;
[navigationBar setFrame:frame];
}
Run Code Online (Sandbox Code Playgroud)
尝试使用 -
CGFloat navBarHeight = 10.0f;
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, navBarHeight);
[self.navigationController.navigationBar setFrame:frame];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81993 次 |
| 最近记录: |