That's it for now, I think I've covered most of the basic questions about UIColor.įeel free to contact me if you have a topic or suggestion that you'd like to see covered here in the blog. You can also use something like R.swift or anything that you prefer. Usually I'm grouping together fonts, colors etc inside structs, but this is just one way of doing things. Now let's reverse the situation and let me show you how to get back these components from an actual UIColor instance with the help of an extension. UIColor(hue: 0.3, saturation: 0.5, brightness: 0.5, alpha: 1) this is just about the same gray color but it's more readable UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 1)Īlternatively you can use HSB values, almost the same logic applies for those values, except that hue goes from 0 'til 360 (because of the actual color wheel), however saturation and brightness are measured in a "percent like" format 0-100, so you have to think about these numbers if you map them to floating point values. So you can make a color with RGB codes using the same logic. If you are working with RGB colors you usually define your color the same way, except that in iOS the values are between 0 and 1, but that's just a different representation of the fraction of 255. You can write hexadecimal notation in Swift using 0x prefix, e.g 0xFF. □īack then without any CS knowledge I was always wondering about the numbers between 0 and 255 that I had to pick. uicolor Share Improve this question Follow edited at 9:34 gi097 7,363 3 28 49 asked at 11:48 Stephen Fox 14.2k 19 49 52 1 ffffff are actually 3 color components in hexadecimal notation - red ff, green ff and blue ff. I've used Microsoft Paint a lot, and I loved it. For example, sRGB is a particular set of intensities for red, green and blue and defines the colors that can be reproduced by mixing those ranges of red, green and blue.Įnough from the theory, let's do some color magic! □□□ How to work with UIColor objects using RGBA and HSBA values in Swift?ĭo you remember the old Paint program from old-school Windows times? □Ī color space is the set of colors which can be displayed or reproduced in a medium (whether stored, printed or displayed). Usually you are going to work with the RGBA & HSBA color models which are basically the same as above extended with the alpha channel where the letter A stands for that. There are several other color models, but if you are dealing with iOS colors you should be familiar with these two above. A color model is a method of describing a color.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |