添加barButtonItem的注意点

    let leftBarBtn = UIBarButtonItem(title: "", style: .plain, target: self,
                                     action: #selector(backToPrevious))
    leftBarBtn.image = UIImage(named: "back")
     
    //用于消除左边空隙,要不然按钮顶不到最前面
    let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil,
                                 action: nil)
    spacer.width = -10;
    //特别注意:这里必须添加之后才能生效 
    self.navigationItem.leftBarButtonItems = [spacer, leftBarBtn]

你可能感兴趣的:(添加barButtonItem的注意点)