Ios 我不知道';t在swift中使用带有AKSideMenu的自定义导航栏
我想使用我的自定义导航栏,我做板上的所有设置,但是当我运行我的应用程序时,就像我转到不同页面时一样,标准导航栏以标准设置出现 我已经尝试添加带有代码的导航栏 此代码块是Ios 我不知道';t在swift中使用带有AKSideMenu的自定义导航栏,ios,swift,swift4.2,Ios,Swift,Swift4.2,我想使用我的自定义导航栏,我做板上的所有设置,但是当我运行我的应用程序时,就像我转到不同页面时一样,标准导航栏以标准设置出现 我已经尝试添加带有代码的导航栏 此代码块是LeftMenuViewController import UIKit public class LeftMenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var tableView: UITableV
LeftMenuViewController
import UIKit
public class LeftMenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var tableView: UITableView?
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override public func viewDidLoad() {
super.viewDidLoad()
let tableView = UITableView(frame: CGRect(x: 0, y: (self.view.frame.size.height - 54 * 5) / 2.0, width: self.view.frame.size.width, height: 54 * 5), style: .plain)
tableView.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleWidth]
tableView.delegate = self
tableView.dataSource = self
tableView.isOpaque = false
tableView.backgroundColor = .clear
tableView.backgroundView = nil
tableView.separatorStyle = .none
tableView.bounces = false
self.tableView = tableView
self.view.addSubview(self.tableView!)
}
// MARK: - <UITableViewDelegate>
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
switch indexPath.row {
case 0:
self.sideMenuViewController!.setContentViewController(UINavigationController(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "haberlerVC")), animated: true)
self.sideMenuViewController!.hideMenuViewController()
case 1:
self.sideMenuViewController!.setContentViewController(UINavigationController(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "duyurularVC")), animated: true)
self.sideMenuViewController!.hideMenuViewController()
case 2:
self.sideMenuViewController!.setContentViewController(UINavigationController(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "firmalarVC")), animated: true)
self.sideMenuViewController!.hideMenuViewController()
case 3:
self.sideMenuViewController!.setContentViewController(UINavigationController(rootViewController: self.storyboard!.instantiateViewController(withIdentifier: "birimlerVC")), animated: true)
self.sideMenuViewController!.hideMenuViewController()
default:
break
}
}
// MARK: - <UITableViewDataSource>
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 40
}
public func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection sectionIndex: Int) -> Int {
return 7
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier: String = "Cell"
var cell: UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: cellIdentifier)
cell!.backgroundColor = .clear
cell!.textLabel?.font = UIFont(name: "HelveticaNeue", size: 21)
cell!.textLabel?.textColor = .white
cell!.textLabel?.highlightedTextColor = .lightGray
cell!.selectedBackgroundView = UIView()
}
var titles = ["Haberler", "Duyurular", "Firmalar", "Yönetim Kurulu", "Bölge Müdürlüğü", "Hizmet Birimleri", "Öneri Şikayet"]
var images = ["haberler", "duyurular", "firmalar", "yonetim", "bolgemudurlugu", "birimler", "oneri" ]
cell!.textLabel?.text = titles[indexPath.row]
cell!.imageView?.image = UIImage(named: images[indexPath.row])
return cell!
}
}
错误是可见的
首先运行我的自定义导航栏
点击不同菜单页面或同一页面
如果我没有错,您希望在所有UIViewController中都有自己的自定义导航栏 打开你的AppDelegate。在下面添加代码
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let color : UIColor = UIColor.white
let buttonFont : UIFont = UIFont.systemFont(ofSize: 14.0)
let titleFont : UIFont = UIFont.systemFont(ofSize: 18.0)
let attributes = [
NSAttributedStringKey.foregroundColor : color,
NSAttributedStringKey.font : buttonFont
]
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedStringKey.foregroundColor : color,
NSAttributedStringKey.font : titleFont
]
UINavigationBar.appearance().barTintColor = UIColor.blue
UINavigationBar.appearance().tintColor = UIColor.white
return true
}
不知道你在问什么。甚至问题的标题本身也不是问题。AKSideMenu是github的一个pod,我使用它,但我想使用我的custum导航栏。当我在AKsidemenu中使用自定义导航栏时,我看不到我的客户导航栏,只显示标准导航栏。对不起,我的英语不是很好。谢谢@channu,你理解了,它工作正确,但我没有使用prefers大号标题,你对使用prefers大号标题有什么建议吗?我做这部分,func setupNavBar(){navigationController?.navigationBar.PrefersTargetTitles=true navigationItem.LarGetTitleDisplayMode=.always navigationController?.navigationBar.LarGetTitleTextAttributes={[NSAttribute String.Key.foregroundColor:UIColor.white]}()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let color : UIColor = UIColor.white
let buttonFont : UIFont = UIFont.systemFont(ofSize: 14.0)
let titleFont : UIFont = UIFont.systemFont(ofSize: 18.0)
let attributes = [
NSAttributedStringKey.foregroundColor : color,
NSAttributedStringKey.font : buttonFont
]
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedStringKey.foregroundColor : color,
NSAttributedStringKey.font : titleFont
]
UINavigationBar.appearance().barTintColor = UIColor.blue
UINavigationBar.appearance().tintColor = UIColor.white
return true
}