May*_*ani 36 iphone xcode objective-c ios swift
我正在开发一个应用程序,我需要保留一个导航栏.当我在酒吧写任何标题时,时间和标题有点彼此非常接近.我想增加酒吧的高度,这样就可以获得一些喘息空间.
Anb*_*hik 38
选择您的视图控制器 - >选择您的导航项目 - > 提示符 - >添加空间也增加了height的**Navigation bar**
编程方式
在viewWillAppear或viewDidAppear 方法中添加它
Objective-C的
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, self.view.frame.size.width,80.0)];
Run Code Online (Sandbox Code Playgroud)
迅速
self.navigationController.navigationBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 80.0)
Run Code Online (Sandbox Code Playgroud)
斯威夫特-3
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 80.0)
Run Code Online (Sandbox Code Playgroud)
iOS 11
目标C.
for (UIView *subview in self.navigationController.navigationBar.subviews) {
if ([NSStringFromClass([subview class]) containsString:@"BarBackground"]) {
CGRect subViewFrame = subview.frame;
// subViewFrame.origin.y = -20;
subViewFrame.size.height = 100;
[subview setFrame: subViewFrame];
}
}
Run Code Online (Sandbox Code Playgroud)
迅速
for subview in (self.navigationController?.navigationBar.subviews)! {
if NSStringFromClass(subview.classForCoder).contains("BarBackground") {
var subViewFrame: CGRect = subview.frame
// subViewFrame.origin.y = -20;
subViewFrame.size.height = 100
subview.frame = subViewFrame
}
}
Run Code Online (Sandbox Code Playgroud)
Nav*_*han 15
请参考苹果推荐的扩展导航栏方法,
https://developer.apple.com/library/content/samplecode/NavBar/Introduction/Intro.html
Meg*_*iya 11
这个解决方案在Xcode 8.xx及更高版本中不再有效!
您还可以在不创建自定义导航的情况下增加高度,请执行以下步骤
步骤1在Storyboard或XIB中选择导航栏
步骤2从Identity Inspector复制ObjectID
步骤3打开Storyboard/XIB作为源代码
步骤4在搜索中通过ObjectID查找源代码中的ObjectID
第5步编辑高度!就这样
我希望这能帮到您
odm*_*odm 10
将以下扩展名添加到项目中:
import UIKit
extension UINavigationBar {
override open func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width: UIScreen.main.bounds.size.width, height: 80.0)
}
}
Run Code Online (Sandbox Code Playgroud)
在viewWillAppear方法中添加它
CGFloat height = 80;
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0,
self.view.frame.size.width,height)];
Run Code Online (Sandbox Code Playgroud)
如果它先增加并缩小到原始高度,则在viewDidAppear方法中添加此代码
小智 8
只需将此行添加到您的 viewController
navigationController?.additionalSafeAreaInsets.top = 30
// where 30 is the extra space, add as per your need.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
59247 次 |
| 最近记录: |