问题
I uses an image for my tabbar selectionIndicatorImage. It works great in Portrait orientation. However, when I change to Landscape orientation, the selectionIndicatorImage is still using the image for Portrait. Therefore, the image's width doesn't fit my Tab bar size in Landscape.
How can I fixed this problem? Thank you.
回答1:
I would change the image from code depending on the orientation. Like this:
// 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")
}
}
来源:https://stackoverflow.com/questions/29191574/how-to-make-uitabbar-selectionindicatorimage-change-when-changing-orientation