Given: A main app, 'Main' and a linked framework 'Icons' in Swift 4 and Xcode 10.
Problem: In main app on storyboard, images from Icons framework display but do not show proper tint.
- Icons framework has an xcassets with icon images all rendered as template
- Icons framework has been linked into and embedded into Main
- Icons.xcassets has been copied by reference into Main
Here is the class from Icons framework that initializes the image for use in Main:
public class KeyWordItem {
public let keyWord:String
public let keyWordImage:UIImage
public let keyWordPrompt:String
/// A failable initializer for a keyword item. nil will be returned if the icon image is not found.
///
/// - Parameter keyWord: The keyword in lowercase, ie., character, scene, conflict, etc.
public init?(using keyWord:String) {
let bundle = Bundle(for: type(of:self))
guard let prompt = keyWordDictionary[keyWord],
let image = UIImage(named:keyWord, in: bundle, compatibleWith:nil) else {
return nil
}
self.keyWord = keyWord
self.keyWordPrompt = prompt
self.keyWordImage = image.withRenderingMode(.alwaysTemplate)
}
}
Note: The icon images are not in the main bundle so you have to get the bundle from the framework. Additionally, when using a storyboard, the only way I could get the images to render at all in Main was to copy (reference only) Icons framework's xcassets folder into Main.
My preference is to keep the Icons framework as UI-lite as I can so I do not want to include a special ViewController in the framework which then would be used in a Main storyboard by referencing Icons as a module.
As proposed by Augie, the image will render with proper tint if a runtime attribute for tintColor is set in the storyboard, but this seems a little less than elegant. (But, hey, it does solve the problem...)
Question 1: How can I get what is a framework's xcassets images marked as render as template, to properly tint in a storyboard outside of the framework?
Question 2: Is this the best approach to handle the requirement to keep all of my icon's and menu items together and not littered all over my Main App?
Thanks in Advance,