There are two reasons for the color differences that you observed.
- The value set in the Storyboard is RGB (sRGB IEC61966-2.1) , and when encoding
UIColor by RGB, it returns RGB (common RGB) .
Therefore, when you change the color from the storyboard, the values โโare different for RBG types. To get the exact type of change in the RGB RGB Sliders value in the storyboard.
Click on the settings icon that will exactly match the RGB Sliders option. A pop-up menu will appear - select the option General RGB .

Now you can observe an image whose value for RGB
56 186 145
now changes to
49 175 126
Thus, these are the values โโof the desired code.
- The problem with Roundup:
In the code, you pass rounding values โโfor the parameter, for example, in the line below
UIColor(red: 0.22, green: 0.729, blue: 0.569, alpha: 1.0)
Thus, he will make a small change per pixel in the color code. I suggest you divide these values โโby 255 and leave a rounded calculation for the compiler. This will give you the desired color accuracy.
So, now for the new values, the update code will be:
let backgroundColor = UIColor(red: 49.0/255.0, green: 175.0/255.0, blue: 126.0/255.0, alpha: 1.0) self.navigationController!.navigationBar.barTintColor = backgroundColor self.navigationController!.navigationBar.isTranslucent = false
source share