我已通过故事板添加了自定义导航栏。我期待屏幕上的内容自动向下移动。但它完全覆盖了屏幕顶部的内容..是否有一行清晰的代码可以自动在导航栏和视图本身之间创建间距?
答案 0 :(得分:1)
你可能听说过Cocpods,我觉得这是一个更好的方法去cutom导航栏。 您只需要实现协议并提供导航栏所需的规范 仔细阅读以下内容
答案 1 :(得分:0)
只需从viewDidLoad调用此方法:
func createNavBar() {
let leftNavigationButton = UIButton()
leftNavigationButton.setImage(UIImage(named: "ic_back.png"), forState: .Normal)
leftNavigationButton.frame = CGRectMake(10, 10, 20, 15)
leftNavigationButton.addTarget(self, action: "onBackButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
let customBarItem = UIBarButtonItem(customView: leftNavigationButton)
self.navigationItem.leftBarButtonItem = customBarItem;
//set TitleAppIcon
let GR = UITapGestureRecognizer(target: self, action: Selector("headerLogoTapAction:"))
let imageView = UIImageView(frame: CGRect(x: 90, y: 0, width: ((UIScreen.mainScreen().bounds.width)/3), height: 40))
imageView.contentMode = .ScaleAspectFit
let image = UIImage(named: "yourimag.png") //or set title
imageView.image = image
imageView.addGestureRecognizer(GR)
imageView.userInteractionEnabled = true
navigationItem.titleView = imageView
}
希望这会帮助你