user3499627
user3499627

Reputation: 63

Color Palettes from storyboard used programmatically

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.

Upvotes: 1

Views: 515

Answers (1)

Kyle Fleming
Kyle Fleming

Reputation: 579

(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];

Upvotes: 1

Related Questions