Can't programmatically change color set in storyboard as color from xcassets catalog
When a UIView
subClass
like UITableViewCell
is loaded from the Storyboard/Xib
, it applies the attributes specified in Attribute Inspector
to all the subViews
. We have the following callback methods to know when a view is loaded from the Storyboard/Xib
,
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}
override func awakeFromNib() {
super.awakeFromNib()
}
These methods could be good candidates to add/remove a subView but they are not supposed to update the subView's size
or some of attribute inspector
related properties. The recommended method to update subViews is when the super view finishes loading and applying all the attribute inspector
properties and calls layoutSubviews
. So then you should apply any cosmetic change to a subView. e.g,
override func layoutSubviews() {
super.layoutSubviews()
label.textColor = UIColor(named: "HighlightedGreen")
}
For a UITableViewCell
, any object implementing UITableViewDataSource
also guarantees a delegate
method to apply any cosmetic change before the cell is being displayed as below, So this is also another good candidate to change the color.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
(cell as! MyListTableViewCell).label.textColor = UIColor(named: "HighlightedGreen")
}
Image asset catalog color not changing
Issue 1) That seems issue with Xcode, next releases may come up with fix.
Issue 2) That seems issue with Xcode too.. When I faced that situation I had to add ImageView programmatically which worked. You may also try IBDesignable or Custom class or Extension which changes renderMode property.
Add a custom color palette to Xcode Interface Builder
Yes, you can create and edit a palette in IB and then share it with your team This article has all the details: http://natashatherobot.com/xcode-color-palette/
Edit:
That link has expired. You can see the web archive here: https://web.archive.org/web/20210303015055/http://natashatherobot.com/xcode-color-palette/
But, using named colors in the asset catalog is a better way to go now.
How to change dynamically color used in UIStoryboard
I finally found the solution.. (had to wait for the tool to exist :p).
Crayons
is an Alcatraz
allowing you to re-use some code define color in Storyboard! yeah!
check it out: https://github.com/Sephiroth87/Crayons
iOS UILabel textColor not updating in dark mode
Somehow the label in collection view is not working as expected. I tried different configurations and none worked. I ended up using button instead and it worked in my case. I will update my answer once I get this working with a label.
Related Topics
Swift Turn a Country Code into a Emoji Flag via Unicode
How to Export Dae Files for Use in Scene Kit Without Seeing "Untitled-Animations"
Swiftui. How to Change the Placeholder Color of the Textfield
How to Add an Event in the Device Calendar Using Swift
Ui Test Deleting Text in Text Field
How to Set a New Root View Controller
How to Satisfy Swift Protocol and Add Defaulted Arguments
Using Some Protocol as a Concrete Type Conforming to Another Protocol Is Not Supported
Best Way to Make Amazon Aws Dynamodb Queries Using Swift
Use Resources in Unit Tests with Swift Package Manager
Uitableview Load More When Scrolling to Bottom
Order of Modifiers in Swiftui View Impacts View Appearance
How to Reason When I Have to Choose Between a Class, Struct and Enum in Swift
Scrollview + Navigationview Animation Glitch Swiftui
Do Capture Lists of Inner Closures Need to Redeclare 'Self' as 'Weak' or 'Unowned'