簡體   English   中英

更改方向時如何更改UITabbar selectionIndicatorImage-Swift

[英]How to make UITabbar selectionIndicatorImage change when changing orientation - Swift

我將圖像用於標簽欄的selectionIndicatorImage。 它在縱向方向上效果很好。 但是,當我更改為“橫向”方向時,selectionIndicatorImage仍將圖像用於“縱向”。 因此,圖像的寬度不適合我在“橫向”中的選項卡欄大小。

在肖像

在風景

我該如何解決這個問題? 謝謝。

我會根據方向從代碼更改圖像。 像這樣:

// the function is called everytime bounds change
override func viewDidLayoutSubviews() {
    let orientation = UIDevice.currentDevice().orientation
    if orientation == .Portrait {
        // I asssume you get images from Images.xcassets
        self.tabBarController?.tabBar.selectionIndicatorImage = UIImage(named: "image1")
    } else if orientation == .LandscapeLeft || orientation == .LandscapeRight {
        self.tabBarController?.tabBar.selectionIndicatorImage = UIImage(named: "image2")
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM