在我的 iOS 应用程序中,我有一个带有几个导航控制器的 tabBarController。在 applicationDidFinishLaunchingtabBarController.selectedViewController是null. 这是在我将导航控制器分配给 tabBar 的 tabBarItems 之后。
什么是合适的默认值tabBarController.selectedViewController?
也许它可以设置为第一个导航控制器。可能需要小心从后台启动的应用程序(在这种情况下,用户可能没有在第一个导航控制器上离开)。
我无法将 RGB 颜色设置为UINavigationBarToolBar。我尝试过这个
let myColor = UIColor(red: 47, green: 206, blue: 255, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor = myColor
self.navigationController?.toolbar.tintColor = myColor
Run Code Online (Sandbox Code Playgroud)
我也试过 HSB 颜色
let secondColor = UIColor(hue: 194, saturation: 82, brightness: 100, alpha: 1.0)
self.navigationController?.navigationBar.barTintColor = secondColor
self.navigationController?.toolbar.tintColor = secondColor
Run Code Online (Sandbox Code Playgroud)
但是当我编写以下方法时它起作用了。
self.navigationController?.navigationBar.barTintColor = UIColor.greenColor()
self.navigationController?.toolbar.tintColor = UIColor.greenColor()
Run Code Online (Sandbox Code Playgroud)
如何将 RGB 颜色设置为条形?
我有一个嵌入在 UITabBarController 上的 UINavigationController。我的目标是更改 UINavigationController 导航栏的标题,同时也将标题保留在 UITabBarItem 上。尝试使用以下命令更改嵌入在 UINavigationController 上的 UIViewController 的标题:
self.title = @"NavBarTitle";
Run Code Online (Sandbox Code Playgroud)
它确实有效,但这也会改变 UITabBarItem 的标题。有没有办法将这两个标题分开?谢谢!
我想为我的 UIViewController 添加标题:
我试过了
self.navigationController.navigationItem.title
self.navigationController.title
self.title
Run Code Online (Sandbox Code Playgroud)
有时,解决方案 1 有效,有时解决方案 2 有效,有时解决方案 3 有效。
哪位专家能告诉我它们之间的区别吗?
uinavigationbar uinavigationcontroller uinavigationitem ios swift
我在AppDelegate. 在我的其中之一中,我ViewController's试图以不同的方式设置属性 - 但是当我使用其他 VC 时,它们仍然有效。
实现这一点的正确方法是什么?
AppDelegate.swift
UINavigationBar.appearance().titleTextAttributes = [
NSFontAttributeName: UIFont(name: "MuseoSans-500", size: 19)!,
NSForegroundColorAttributeName: UIColor.white
]
UINavigationBar.appearance().tintColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
SharkViewController.swift
// MARK: - View Did Load
override func viewDidLoad() {
super.viewDidLoad()
UINavigationBar.appearance().titleTextAttributes = [
NSFontAttributeName: UIFont(name: "MuseoSans-500", size: 19)!,
NSForegroundColorAttributeName: UIColor.black
]
}
Run Code Online (Sandbox Code Playgroud) uinavigationbar uiviewcontroller uinavigationcontroller ios swift
我只想自定义导航栏标题的特定部分。
例如,“导航栏标题”。我把这句话当成了标题。
在“导航”的情况下,应用蓝色和系统粗体字体,对于“栏标题”。我想应用红色和系统常规字体。
这怎么可能?
一切都以编程方式进行。没有Storyboard,并且Collection视图的vc和详细的vc都在TabBarController中。
我正在使用集合视图,当我点击一个单元格时,didSelectItem我按下了一个详细的视图控制器。在DetailedVC中,我隐藏了导航控制器。我叫下面的viewDidLoad和viewWillAppear单独和累积,试图掩盖它:
navigationController?.isNavigationBarHidden = true
navigationController?.navigationBar.isHidden = true
navigationController?.setNavigationBarHidden(true, animated: false)
Run Code Online (Sandbox Code Playgroud)
场景首次出现时,导航栏被隐藏。问题是,当我在“ DetailedVC”上向下滑动时,导航栏会从屏幕顶部向下滑动,并且不会消失。我是通过误刷而发现的。
我按下导航栏的“后退”按钮,即使它应该隐藏也可以使用。我之所以隐藏它,是因为我有一个视频在“ DetailedVC”的最上方播放,所以我使用一个自定义按钮来弹出到收藏夹视图。我还隐藏了状态栏(类似于YouTube),但仍处于隐藏状态。
DetailedVC是常规视图控制器,并且不包含表视图或集合视图,因此我对为什么它让我向下滑动以及为什么导航栏不会保持隐藏状态感到困惑?
收集视图单元格,将DetailVC推入:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailVC = DetailController()
navigationController?.pushViewController(detailVC, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
详细的VC:
class DetailController: UIViewController {
let customButton: UIButton = {
let button = UIButton(type: .system)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("< Back", for: .normal)
button.setTitleColor(UIColor.orange, for: .normal)
button.addTarget(self, action: #selector(handleCustomButton), for: .touchUpInside)
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white …Run Code Online (Sandbox Code Playgroud) uinavigationbar uiviewcontroller uinavigationcontroller ios swift
我有一个显示视图控制器的按钮(ViewControllerIncluirItem).但是,我需要在导航之前检查一个条件,我尝试在func中检查这个override func prepare(for segue: UIStoryboardSegue, sender: Any?).但是,导航只能以任何方式发生.我试过这个:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SegueToVcIncluirItem" {
if pricelist != nil {
print("pricelist ok")
} else {
print("selecione pricelist")
return // Here I want prevent.
}
let nav = segue.destination as! UINavigationController
let childVc = nav.topViewController as! ViewControllerIncluirItem
childVc.strTeste = "testado com sucesso"
}
}
Run Code Online (Sandbox Code Playgroud) 我需要在我的navigationController的左侧为我的应用程序创建一个“汉堡菜单”按钮,但是由于NavCon是透明的,因此我的图标上需要有一个阴影。
因此,我创建了一个带有图像,阴影的自定义UIButton,并将其添加为UIBarButtonItem上的自定义视图,如下所示:
let menuButton = UIButton(type: .custom)
menuButton.addTarget(self, action: #selector(showSideMenu), for: .touchUpInside)
menuButton.setImage(#imageLiteral(resourceName: "menu_white"), for: .normal)
menuButton.tintColor = UIColor.white
menuButton.layer.masksToBounds = false
menuButton.layer.shadowColor = UIColor.black.cgColor
menuButton.layer.shadowOpacity = 1.0
menuButton.layer.shadowRadius = 5
menuButton.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: menuButton)
Run Code Online (Sandbox Code Playgroud)
上面的代码在iOS 11上运行良好,但是当我在ios 9和10(模拟器和真实设备)上测试我的应用程序时,菜单图标不可见。它是可单击的,并且按预期方式工作,但是没有可见的图标。
在View Hierarchy Debugger中,我可以看到宽度和高度为0的UIButton,而在ios 11中,我可以看到带有嵌入式UIButton的普通UIButtonBarStackview。
关于如何解决此问题以及为什么会发生的任何想法?非常感谢你!
我目前正在迅速开发iOS应用程序。在这里,我UIView位于屏幕顶部并具有UINavigationController。而且我需要topView和navigationBar颜色相同。而且我给了topBar背景色和navigationBar着色色相同。但是,当屏幕加载时,navigationController会显示褪色。为什么?我以编程方式尝试了一下,
self.navigationController?.navigationBar.barTintColor = UIColor.red
Run Code Online (Sandbox Code Playgroud)
另外,我尝试了演示图板,例如将navigationBar的tintColor设置为红色。但是从两种方式来看,它都无法正常工作。请帮我。