Flip UIImageViews for Right to Left Languages

后端 未结 7 1476
悲&欢浪女
悲&欢浪女 2021-02-13 02:31

iOS automatically flips the entire ViewController when using a RTL language like Arabic and does a great job with most of the layout, especially text. The default b

7条回答
  •  无人及你
    2021-02-13 02:56

    Swift 5

    If you want to individualize the image flip, you can register each image with the direction you want since the layout direction is a trait:

    let leftToRight = UITraitCollection(layoutDirection: .leftToRight)
    let rightToLeft = UITraitCollection(layoutDirection: .rightToLeft)
    let imageAsset = UIImageAsset()
    let leftToRightImage = UIImage(named: "leftToRightImage")!
    let rightToLeftImage = UIImage(named: "rightToLeftImage")!
    imageAsset.register(leftToRightImage, with: leftToRight)
    imageAsset.register(rightToLeftImage, with: rightToLeft)
    

    This is the same as configuring it in the asset catalogue as @SergioM answered.

提交回复
热议问题