Search code examples
iosinterface-builder

"Named colors do not work prior to iOS 11.0" error referring to a storyboard


While developing an iOS application for targets below iOS 11, I accidentally left a named color in one of my storyboards. However, the error I got only shows the name of the storyboard and not the exact view that is causing the issue:

Error, text transcription: see below

Named colors do not work prior to iOS 11.0
Main.storyboard

How can I find the exact views that have a named color as a property and replace those with a non-named color?


Solution

  • If you want to get the exact floating point values of your named colours, and then do a find / replace so that you can do a quick "replace all" instead of editing each individual colour. Just search for "namedColor" in your storyboard and you will find the colorus as they would appear normally eg.

    <namedColor name="Grey Background">
         <color red="0.92941176470588238" green="0.93333333333333335" blue="0.94117647058823528" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
    </namedColor>
    

    Then do a Find/Replace with the search term:

    name="Grey Background"/>
    

    And copy-paste the following into the "With" section of the Find / Replace:

    red="0.92941176470588238" green="0.93333333333333335" blue="0.94117647058823528" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
    

    Then hit "replace all". Don't forget to include the "/>" at the end of both the search term and the replacement text as this will ensure the name is not replaced in the "namedColor" section at the bottom of the storyboard document.

    This should then replace all colours in your storyboard that match the exact name. Now just right-click the storyboard and open in interface builder again and the file will recompile and all colours should still look the same.

    Things to note:

    1. Always make sure you either commit then push to your repository or at least make a backup copy of your storyboard file before you make any changes to it's source.
    2. Do this same process for all .xib files that may contain the named colours too otherwise your project wont compile.
    3. You can use this same process if you ever have to change a colour project-wide without having to change it for each individual view. Just do a find / replace for the RGB values you pasted above and this will allow you to do a "replace all" for that colour in the future.