2016-10-04 60 views
0

我使用iOS 9約束來以編程方式設置我的應用程序的佈局。我明白創建一個導航欄編程我做了以下內容:如何根據設備更改導航欄的大小?

let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: My_Height)) 

的事情是,我想的導航欄的高度改變的設備改變,使其使用約束比例。我會怎麼做呢?

回答

0

你必須設置高度不變,以約束編程製作的出口,並且計算比例

+0

我該怎麼做呢? –

+0

@property(弱,非原子)IBOutlet NSLayoutConstraint * heightConstraint; – Ashish

+0

創建IBOutlet並根據設備高度計算比例值 – Ashish

0

您可以使用此屏幕尺寸:

var screenWidth: CGFloat { 
    if UIInterfaceOrientationIsPortrait(screenOrientation) { 
     return UIScreen.mainScreen().bounds.size.width 
    } else { 
     return UIScreen.mainScreen().bounds.size.height 
    } 
} 
var screenHeight: CGFloat { 
    if UIInterfaceOrientationIsPortrait(screenOrientation) { 
     return UIScreen.mainScreen().bounds.size.height 
    } else { 
     return UIScreen.mainScreen().bounds.size.width 
    } 
} 
var screenOrientation: UIInterfaceOrientation { 
    return UIApplication.sharedApplication().statusBarOrientation 
} 

然後,您可以自定義導航的尺寸取決於屏幕的高度或寬度。

相關問題