Make a UIColor with RGB values? or this might be a problem with loading my view...not

Discussion in 'iOS Programming' started by stoopkitty, Apr 2, 2011.

  1. macrumors member

    Jan 26, 2010
    I recently decided i wanted to get rid of xibs all together and just create my view programatically. i am a little confused as to how to do this.

    so i know you can use [UIColor colorWithRed:1.00 green:1.00 blue:1.00 alpha:1.00] to make a color (for that example, white) and instead of using the normal 0-255 scale they use the percentages for some reason which is fine.

    to simplify this, i made a method in MainView.m/h (below) that accepted the 0-255 RGB values and returns a UIColor with those values:
    - (UIColor *)RGBColorR:(double)red G:(double)green B:(double)blue {
        return [UIColor colorWithRed:(red/255.00) green:(green/255.00) blue:(blue/255.00) alpha:1.00];
    I call it in my loadview method in my view controller:
    - (void)loadView {
        self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        self.view.backgroundColor = [self RGBColorR:236 G:229 B:206];
    Note: I do not have a MainView.xib at all, I deleted it.

    For some reason, it always comes up with a bright green color as the background and doesnt load of the text fields or buttons or anything i later add to the view. What is the proper way to do this... i am confused.
  2. macrumors 6502

    Oct 31, 2007
    San José
    What if you choose not to override loadView, let the view controller create the view, then put all of the other code in viewDidLoad?

Share This Page