2

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,

wm_j_ray
  • 144
  • 7
  • I like this idea. sorry I don't know what how to resolve the issue. Did you try answer here? https://stackoverflow.com/questions/41121425/uiimageview-doesnt-always-tint-template-image – Augie Oct 08 '18 at 15:53
  • Yes, I saw your reference and it does solve the problem using a runtime attribute. As an aside, I tried adding layout constraints as discussed but those didn't work. My preference is not to have to set a runtime for tintColor every time I use an asset from a framework. Seems sort of hack-ie to me. I'm not sure if I'm missing something, doing something incorrectly, or if this is an issue with IB and storyboards. (I'm going to leave the question as open for the time being as maybe there is a more elegant solution not so tightly coupled to Storyboard. – wm_j_ray Oct 08 '18 at 16:01

0 Answers0