Forum Archive

How do you set a color with objc?

cook

I want to set a color in objc... Not sure what it needs.

I'm working on UISlider...
This doesn't work:

setThumbTintColor_(ui.parse_color('#566565'))

@omz @jonb

JonB

when dealing with objc, you usually need to look up the reference page from Apple to see what the arguments types are.

In this case, it takes a UIColor. Objc_util comes with UIColor already aliased for you. Poke around the UIColor.... autocomplete in the console, and you may find some useful ones.

S.thumbTintColor=UIColor.colorWithRed_green_blue_alpha_(0.4,.2,.01,1)
or, for example
S.thumbTintColor=UIColor.colorWithHexString_('ff1aa0')

UIVolor also has a bunch of "named colors" like UIColor.redColor(), etc.

cook

@JonB thank you! Good to know!