Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Define a Custom Color That Is Available Both Programmatically And In IB?

Tags:

xcode

ios

I want to be able to define a custom color in a single place and then have access to it both programmatically and in Interface Builder. For coding I could create a UIColor extension. For visual designing in IB I could create a custom color palette. What is the best technique that will simultaneously work with both?

like image 908
Verticon Avatar asked Dec 19 '22 05:12

Verticon


2 Answers

Unfortunately you can't do this.

You can define a colour that you can access in code through an extension of UIColor. Or you can add a colour to the pallets in Interfact Builder.

But you can't have both.

Hmm...

What you could do is something similar to what PaintCode does.

Create an object in code that has a IBOutletCollection and then when the view loads it will iterate the outlets and set the background colour etc... to your fancy colour.

like image 173
Fogmeister Avatar answered May 08 '23 02:05

Fogmeister


Xcode 9 allows you to place colors in the Asset catalog. This is Apple's answer to those who want to have their colors synced across both.

like image 40
Ryan Poolos Avatar answered May 08 '23 02:05

Ryan Poolos