我正在构建一个使用自定义导航栏的应用,如图所示
我无法更改标签的位置,例如" My Xyz business"。我想把标签推到屏幕的顶部(现在它正朝着酒吧的底部拥抱)
我尝试过代码但只改变了高度和宽度。 x和y位置没有变化。
为什么会发生这种情况
以下是代码:
func customNavigationBar(){
var ver: [AnyObject] = UIDevice.currentDevice().systemVersion.componentsSeparatedByString(".")
if CInt(ver[0] as! String)! >= 7 {
// iOS 7.0 or later
self.navigationController!.navigationBar.barTintColor = UIColor.whiteColor()
self.navigationController!.navigationBar.translucent = false
}
else {
// iOS 6.1 or earlier
self.navigationController!.navigationBar.tintColor = UIColor.whiteColor()
}
self.navigationController!.navigationBar.frame = CGRectMake(0, 0,400 , 174)
let lbl: UILabel = UILabel(frame: CGRectMake(0, 0, 200, 30))
lbl.font = UIFont(name: "Vodafone Rg", size: 20.0)
lbl.text = "My Xyz Inc Business"
lbl.textColor = UIColor(red: 230.0 / 255, green: 0, blue: 0, alpha: 1.0)
let vodafoneLabel: UIBarButtonItem = UIBarButtonItem(customView: lbl)