Wednesday, September 12, 2018

iOS Framework, how to load an image

Loading an image from the framework bundle does not work in below way

UIImage.init(named:"imagename")

this is because the reference to the bundle is going to be the main bundle and the image may be not in the xcassets  of the main bundle, instead it may be only in the bundle of the framework. Below to be used for loading image in a bundle

let icon = UIImage.init(named: "back", in: Bundle(for: A2ChatVC.self),compatibleWith: nil)?.withRenderingMode(.alwaysOriginal)

No comments:

Post a Comment