Graphics, UIColor created with component values far outside the expected range

IosImageGraphics

Ios Problem Overview


I got Xcode 8 and a folder with images. I have replaced all images with specific filters in Photoshop, Pixalate.

When I run my project, I get an error:

> [Graphics] UIColor created with component values far outside the expected range, Set a breakpoint on UIColorBreakForOutOfRangeColorComponents to debug. This message will only be logged once.

How can I solve this?

Ios Solutions


Solution 1 - Ios

You might have something like this somewhere :

UIColor(red: 255, green: 255, blue: 255, alpha: 1.0)

need to be changed like this now :

UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
SO : UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0)

Solution 2 - Ios

As mentioned in your warning info, you just set the value outside the expected range. According to the API Reference, every parameter pass to UIColor generator should be between 0.0 and 1.0.

You can follow the steps bellow to find out the code which cause this warning:

Step 1: add a Symbolic Breakpoint in your breakpoint navigator add a Symbolic Breakpoint

Step 2: set the symbol of the Symbolic Breakpoint to be UIColorBreakForOutOfRangeColorComponents set the symbol of the Symbolic Breakpoint

Step 3: run your app to get the call stack

Follow the call stack of step 3, you will find the key code results in the warning.

Solution 3 - Ios

Short answer: RGB values go from 0-1. You probably entered the straight number. Divide each value by 255.

Long answer: I got this error. I had looked up a color in RGB. This was my code.

view.backgroundColor = UIColor(red: 125, green: 125, blue: 125, alpha: 1)

I used the symbolic breakpoint trick to find which line it was breaking on, but I still didn't know how to fix it.

Then looking at another answer here, I remembered that RGB values have a range of 0-1. The numbers that are given are always divided by 255.

I changed my code to this:

view.backgroundColor = UIColor(red: 125/255, green: 125/255, blue: 125/255, alpha: 1) and it worked great.

Solution 4 - Ios

Try this out. It worked fine for me

UIColor(red: <Your color>/255.0, green: <Your color>/255.0, blue: <Your color>/255.0, alpha: 1.0)

Solution 5 - Ios

Answer: RGB values always should be in range like 0-1. You probably entered the straight number and Divide RGB color value by 255.

e.g.

UIColor(displayP3Red: 41/255.0, green: 128/255.0, blue: 185/255.0, alpha: 1.0)

its working...:)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDoneView Question on Stackoverflow
Solution 1 - IosPatrice From 8BeatsView Answer on Stackoverflow
Solution 2 - IosrobyView Answer on Stackoverflow
Solution 3 - IosJoshua DanceView Answer on Stackoverflow
Solution 4 - IosSyngmasterView Answer on Stackoverflow
Solution 5 - IosParthView Answer on Stackoverflow