Xcode: Launch screen changes color without premission - ios

After adding launch screen, I discovered the color of it is slightly different than what I specify, I chose R:31,G:174,B:240,A:1, but I noticed it is slightly a different color on the device (I took a screenshot and used a color picker to determine what color it is exactly), this drives me crazy, what can I do?

try setting the numbers over 255.
so:
UIColor(red: 31/255, green: 174/255, blue: 240/255, alpha: 1.0)
RGB is based of 255 and need a floatNumber.

Related

XCode 12.2 color literal from assets

Before if we drag assets colorliteral we can see the color with rgb but now if we drag color from assets it shows syntax like "color("filename"), how can i get old xcode like result in xcode 12.2 https://imgur.com/u2nloNW
It's not ideal but you can use UIColor(named: "CaseTypePrivate")
I can't seem to find any way to get the #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) that we used to get when you drag-and-dropped from the assets menu.
One bonus at least of the first answer is that it will reflect any changes you make to your color assets; whereas the colorLiteral approach effectively hard-codes the color value.

iOS-Charts Library: BarChart background color fill

I am using a Charts library by Daniel Gindi.
I need to make a diagram like in this screenshot. Set a different background color. Could you do that? I looked at the library and found no way to do this.
Thanks.
There is a nice tutorial on AppCoda for iOS charts by Daniel Gindi.
"If you want a different color for each data entry, then you have to provide as many colors as the total number of data entries you have".
In order to change the color of the bar chart, you'll need to change the color of the dataset you're representing. Like so:
chartDataSet.colors = [UIColor(red: 230/255, green: 126/255, blue: 34/255, alpha: 1)]
If you mean to change the chart's background color, you need to put this in your code:
chart.backgroundColor = .white
Look, I specifically added the same arrays of data, and I added them to one bar chart. What I mean is that the same values alternate. They aren't represented one after another. So, it means that if you had a different background color for each bar, this wouldn't probably look nice imho.
I hope someone else will try to reproduce your question so that we have more opinions here :)
Use following configuration to barchar
barChart.drawBarShadowEnabled = true
Then use
chartDataSet.barShadowColor = .systemGray5
It works.

Best practices when initializing a UIColor displayP3 color

Is it best to use init(displayP3Red:green:blue:alpha:) by default with an availability check when creating a UIColor? Honestly I can't see the difference between the two so I'm not sure how much it matters, but I was hoping someone could shed some light on this.
if #available(iOS 10.0, *) {
self.init(displayP3Red: r, green: g, blue: b, alpha: a)
} else {
self.init(red: r, green: g, blue: b, alpha: a)
}
No, these calls are not equivalent. Passing the same RGBA values to each will result in different colors.
Here's a handy article discussing the differences in color spaces. It makes the nice analogy of a color space being like units of length on a ruler. If I say some object has a length of 1.0, that doesn't make any sense unless you know how long "1.0" is. Inches? Meters? Furlongs? Parsecs? The definition of the unit makes a huge difference to what the quantity in a measurement means.
Similarly, if I say a color has a red component of 1.0, that doesn't mean anything unless I also say how red 1.0 is. (Ditto for green and blue components.) For much of the history of web and app design, it was safe to assume that all measurements are relative to the sRGB standard — 1.0 red means "as red as sRGB can get".
But with the advent of phones, computers, TVs, etc, supporting much larger color gamuts that assumption is no longer safe. Display P3 is the color space used by newer Apple devices (and closely matches that used by newer 4K HDR TVs). P3 supports a broader range of colors than sRGB, meaning that "as red as sRGB can get" is not red enough.
To make it a little bit easier to interoperate between sRGB and P3 devices, Apple's APIs include an "Extended sRGB" color space. In regular sRGB, as in most color spaces, component values are restricted to the 0.0–1.0 range — that is, you can't have a red component of 1.1, and if you try, you'll just get it clamped down to 1.0. Extended sRGB is defined to be the same as sRGB for component values in the 0.0–1.0 range, but permits using values outside that range to express colors outside the sRGB gamut. (This is what the Apple documentation means when it says UIColor(red:green:blue:alpha:) uses an extended sRGB color space.)
UIColor (and CGColor that sits below it) in iOS don't offer handy utilities for color space conversion, but NSColor in macOS does, which makes it handy for illustrating the difference:
The first red is equivalent to UIColor(displayP3Red: 1, green: 0, blue: 0, alpha: 1) in iOS. The second is equivalent to UIColor(red: 1, green: 0, blue: 0, alpha: 1) in iOS. If you're viewing this answer on a P3 display*, you'll probably notice at least a subtle difference in the color swatches.
And down below, notice the converted values. "sRGB max red", aka UIColor(red: 1, green: 0, blue: 0, alpha: 1) is roughly equivalent to (r: 0.918, g: 0.2, b: 0.139, a: 1) in P3. "P3 max red", aka UIColor(displayP3Red: 1, green: 0, blue: 0, alpha: 1) is outside sRGB, but can be expressed in "extended sRGB" as (r: 1.093, g: -0.227, b: -0.15, a: 1).
* Apple devices with P3 displays include iPhone 7, iPad Pro 2016, iMac fall 2015, MacBook Pro fall 2016, and later
The difference is in the return value:
self.init(displayP3Red: r, green: g, blue: b, alpha: a)
Return a sRGB value:
The color object. The color information represented by this object is
in an extended range sRGB colorspace. On applications linked for iOS 10
or later, the color is specified in an extended range sRGB color space.
self.init(red: r, green: g, blue: b, alpha: a)
Return a RGB value:
The color object. The color information represented by this object is
in an RGB colorspace. On applications linked for iOS 10 or later, the
color is specified in an extended range sRGB color space. On earlier
versions of iOS, the color is specified in a device RGB colorspace.
From: https://developer.apple.com/documentation/uikit/uicolor
The sRGB format is to have the same color on every device.
You can see more detailed example: http://inaka.net/blog/2014/09/05/getting-the-right-colors-in-your-ios-app/

iOS 11 System gray color

I have a UIView directly below my default Navigation Bar and I am trying to make it appear that the region is one. To do this I am trying to match the color of my custom view to the color of the navigation bar. However, it doesn't seem to be any of the UIColors such as gray or lightGray. I would assume that if it is a custom color then I would be able to pull the color from the navigation bar, but I cannot seem to find the value.
you can use digital color picker app available in mac os,
Then whichever component's color you want just hover mouse pointer there and you will get the RGB Values in digital color meter and that RGB values you can use in setting the background of your view,
in this way,
UIColor.init(red: 49.0/255.0, green: 49.0/255.0, blue: 49.0/255.0, alpha: 1.0)

IOS figure out shade of in grey keyboard buttons

IOS default keyboard has the following buttons:
I am trying to make my own custom keyboard and I need to figure out the shade of grey/style (if they use something special to achieve that grey look) of these buttons.
I thought the RGB value was: (170,170,170)
but the UIColor UIColor.init(red: 2/3, green: 2/3, blue: 2/3, alpha: 1)
lends me a darker color that looks like this:
Am I possibly missing a transparency value and if so how can I figure it out?
You can use a color picker to figure it out.
It's (173, 180, 190).

Resources