Color Palettes from storyboard used programmatically - ios

I am building an app and I have multiple colors that I want a background to be depending on a predetermined factor. In my story boar I have tested and chosen the colors I wanted to use and I have put them in a palette on the color picker. First question can I programmatically call on the colors of the palette.
if that doesn't work I have already gotten the RGB values for each of the colors but when I try to go do this:
UIColor *myBlue =[UIColor colorWithRed:(60/255) green:(97/255) blue:(255/255) alpha:1.000];
self.navigationController.navigationBar.barTintColor = myBlue;
self.tabBarController.tabBar.barTintColor = myBlue;
it gives me the same color as of I go
[UIColor blueColor]
the reason I am creating my own color is because I don't want the predetermined colors but they are not showing up.

(This might be a zombie issue, but for anyone else curious)
This is actually a bug because you're performing integer division instead of floating point division. Dividing an int by an int throws away the remainder. You're code is functionally equivalent to:
UIColor *myBlue =[UIColor colorWithRed:0 green:0 blue:1 alpha:1.000];
Which of course is pure blue. To fix, force floating point division by making one of the numbers a float type. For example, you could change that line to:
UIColor *myBlue =[UIColor colorWithRed:(60/255.0) green:(97/255.0) blue:(255/255.0) alpha:1.000];

Related

UIColor display not exactly correct?

I input this in viewDidLoad
self.view.backgroundColor = [UIColor colorWithRed:231/255.0 green:77/255.0 blue:77/255.0 alpha:1.0];
and create label in xib , set color e74d4d(which convert to rgb is 231,77,77)
I want to show image on the website , but it tells me I need 10 reputation.
I debug the code,and find this,
(lldb) po self.view.backgroundColor
UIDeviceRGBColorSpace 0.905882 0.301961 0.301961 1
(lldb) po self.label.textColor
UIDeviceRGBColorSpace 0.87161 0.208926 0.237916 1
while you are passing value for UIColor always use float value.
self.view.backgroundColor = [UIColor colorWithRed:231.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
also use the same float value while you are converting to other format.
Edit: From the comments.
Dividing 231/255.0 and 231.0/255.0 are the same. Yes it is, but i have written that always pass float value means in for both values.
As user doesn't provided second conversation i thought function is using 255 for devision instead of 255.0 as a result it will be a integer value.
Try below code with RGBFromUIColor macro one by one, it will show different output.
self.titleLabel.backgroundColor = [UIColor colorWithRed:231/255 green:77/255 blue:77/255 alpha:1.0];
self.titleLabel2.backgroundColor = [UIColor colorWithRed:231.0/255.0 green:77.0/255.0 blue:77.0/255.0 alpha:1.0];
self.titleLabel3.backgroundColor = RGBFromUIColor(231, 77, 77);
self.titleLabel4.backgroundColor = RGBFromUIColor(231.0, 77.0, 77.0)
Now suppose macro for RGBFromUIColor is like below
#define RGBFromUIColor(r, g, b) \[UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
or like this
#define RGBFromUIColor(r, g, b) \[UIColor colorWithRed:(r)/255 green:(g)/255 blue:(b)/255 alpha:1]
The last RGBFromUIColor will not have same value in case it doen't devided by float i.e 255.0
Your issue is that the text lable colour is not the same as your background colour?
I suspect your problem is that you are setting the text color to e74d4d which is a 24 bit value, no transparency value (the A in RGBA and ARGB). Try ffe74d4d or e74d4dff which set the transparency to opaque (alpha to 1). Even better, simply set it the same way as you set the background color, and iOS will automatically set the transparency to opaque.
This may not be what you are experiencing, but it I have previously seen some color problems with the OS X Color Picker due to the color calibration on my display. Sometimes it seems to select the color components by display value and then convert them to sRGB, when you actually want no conversion at all.
I would try the either of the following:
Use the ‘RGB Sliders’ color picker panel.
Paint the color in an image without a color profile, open the image in Preview.app and use the pipette tool to select that color.

UILabel background color detection?

Is it possible to detect the colour of a particular UILabel programatically?
The intention for these lines of code, is to change the background from a red colour, to a white colour. Increase the brightness for a brief second then reduce the brightness and follow up with a label background colour back to red.
The issue is that sometimes, the brightness will increase without the background colour changing. Thus resulting in a major flaw in the design for the application. Which is private.
self.label.backgroundColor = [UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha: 1.0];
[UIScreen mainScreen].brightness = 1.0;
[self performSelector:#selector(resetColor) withObject:self afterDelay:0.05f ];
- (void)resetColor {
[UIScreen mainScreen].brightness = 0.0;
self.label.backgroundColor = [UIColor colorWithRed:255.0/255 green:0.0/255 blue:0.0/255 alpha:0.5];
Can anyone see why it would randomly not change the background colour beforehand?
And mainly, is it possible to do the following?
if (self.label.backgroundColor == [UIColor whiteColor]){
or
while (self.label.backgroundColor == [UIColor whiteColor){
?
your function:
[self performSelector:#selector(resetColor) withObject:self afterDelay:0.05f ];
which of this function called?
to compare the color are extactly the same:
use isEqual: instead of ==
i.e.
if ([self.label.backgroundColor isEqual:[UIColor whiteColor]])
otherwise, you should compare the all of Color's elements,
i.e. RGBA

UISegmentedControl always appears dim

No matter what settings I try, I cannot get UISegmentedControl to render with the tintColor I set. I took a few screenshots, and it seems whatever color I set, the rendered result is 20% darker (i.e. UIColor whiteColor ends up R:204,G:204,B:204)
I've tried every combination of the settings below, and nothing seems to change the fact it always looks darker. However, inspection of the tintAdjustmentMode at all stages before/after setting the values, appear, etc. comes out as UITintAdjustmentModeNormal. I can make the background color of the text render at full brightness, but the frame and selected index fill is always at 80% brightness. Oddly, this doesn't happen in the 7.1 Simulator, but it does happen on my iPhone 5 with 7.1.1.
Has anyone had similar problems? I've read many other threads about controls not dimming, or people wanting to set different colors for different parts of the control, but couldn't find any about tintColors that won't show at full brightness.
Various settings I've tried individually and together:
UIColor *tintColorToSet = [UIColor colorWithRed:0/255.0f green:241/255.0f blue:1.0f alpha:1.0f];
NSMutableDictionary *textAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
tintColorToSet, NSForegroundColorAttributeName,
[UIColor clearColor], NSBackgroundColorAttributeName,
[UIFont fontWithName:#"NesController" size:18.0f], NSFontAttributeName, nil];
[_lengthBar setTitleTextAttributes:textAttributes forState:UIControlStateNormal];
[textAttributes setValue:[UIColor blackColor] forKey:NSForegroundColorAttributeName];
[_lengthBar setTitleTextAttributes:textAttributes forState:UIControlStateSelected];
_lengthBar.tintColor = tintColorToSet;
_lengthBar.alpha = 1.0f;
_lengthBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
Thanks for the help.

Changing Color Temperature not Brightness of iOS screen

This Question Here was marked a duplicate because the wording of the question was bad. But I have the same question.
I do not want to change the brightness of the screen but change the color temperature of the screen the way the app f.lux does. It eliminates blue light at night time.
Unfortunately, the API it uses is not App Store admissible. But I'm a developer, so as long as I can get the app on my personal devices I would like to write it so I don't have to jailbreak my phone.
Any idea what calls they may be making to tint the entire screen so there is little to no blue light even when in the background?
Looking at the flux sources with nm gives some hints, it loads:
/System/Library/PrivateFrameworks/IOMobileFramebuffer.framework/IOMobileFramebuffer
And references these symbols:
U _IOMobileFramebufferGetGammaTable
U _IOMobileFramebufferGetMainDisplay
U _IOMobileFramebufferSetColorRemapMode
U _IOMobileFramebufferSetGammaTable
A more complete disassembly is provided here:
https://gist.github.com/anthonya1999/e0bffcac15b6b208126d
I guess HUE is the property which corresponds to the color temperature , i was successful changing the hue of an UIImage the below code does the same, i guess this will not exactly answer your question but will give you an idea to get started,
//convert to HSB
CGFloat h, s, l, a;
UIColor *color = [UIColor colorWithRed:r green:g blue:b alpha:1.0f];
[color getHue:&h saturation:&s brightness:&l alpha:&a];
//adjust hue
h *= amount;
//convert back to RGB
color = [UIColor colorWithHue:h saturation:s brightness:l alpha:1.0f];
[color getRed:&r green:&g blue:&b alpha:&a];
This will need some twist to set it in your code.

Setting UIITextView border color

I would like to set the silver color for my UITextView border. I tried this:
theGroupTextLabel.layer.borderWidth = 3.5f;
theGroupTextLabel.layer.borderColor = [[UIColor whiteColor] CGColor];
...but in the color option there are only some colors like whiteColor, BlackColor, Green...
What if I want silver?
You need to use RGB values for custom colors;
CGFloat nRed=128.0/255.0;
CGFloat nBlue=98.0/255.0;
CGFloat nGreen=53.0/255.0;
UIColor *myColor=[[UIColor alloc]initWithRed:nRed green:nBlue blue:nGreen alpha:1];
Choose RGB Values Here
Something around R:193 G:205 B:205 would be close to silver
You will just need to customize your color with RGB values because what you are seeing are just a handful of predefined colors for your convenience. This is an example of a custom color with RGB values.
[[UIColor colorWithRed:0.5f green:0.2f blue:0.7f alpha:1.0f] CGColor]; // Not actually silver
NOTE: Normally you will find a number between 0 and 255 for each value but this function takes floats so just take those number and divide it by 255 to get the float value of what you need.
Try to set you your color like this
theGroupTextLabel.layer.borderWidth = 3.5f;
theGroupTextLabel.layer.borderColor = [[UIColor colorWithRed:(RedRGB.0/255.0)
green:(GreenRGB.0/255.0)
blue:(BlueRGB.0/255.0)
alpha:(AlphaRGB.0/255.0)] CGColor];

Resources