Search code examples
objective-cios7uibuttonxcode6uicolor

Issue with using RGB colors in IOS


I want to use RGB color to set set background color of UIButton.

I have lots of UIButtons so I decided to make a custom class.But when I try to use colorWithRed I am getting error.

First Code:

[self.layer setBackgroundColor:[UIColor colorWithRed:60/255.0f green:146/255.0f blue:180/255.0f alpha:1.0f]];

Error

enter image description here

Second Code

  self.layer.backgroundColor = [UIColor colorWithRed:60/255.0f green:146/255.0f blue:180/255.0f alpha:1.0f];

Error

enter image description here


Solution

  • try to use this code

    self.layer.backgroundColor = [UIColor colorWithRed:60/255.0f green:146/255.0f blue:180/255.0f alpha:1.0f].CGColor;
    

    You need to convert UIColor to CGColor which can be done by above code.

    Hope this will solve your problem