-4

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

Rahul
  • 5,594
  • 7
  • 38
  • 92

2 Answers2

4

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

Malav Soni
  • 2,739
  • 1
  • 23
  • 52
  • It is working..thanx malav...could be please assist me to solve one of my problem – Rahul May 04 '15 at 06:14
  • If you another issue please create another question I will help you there for sure – Malav Soni May 04 '15 at 06:16
  • yes i will..but not here may make a chat room or some where else like gmail.or skype ? – Rahul May 04 '15 at 06:16
  • here is my question http://stackoverflow.com/questions/30001518/issue-while-changing-navigation-root-view-controller?noredirect=1#comment48122826_30001518 – Rahul May 04 '15 at 06:18
  • reputation le k chale gaye :( – Rahul May 04 '15 at 06:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76853/discussion-between-rahulmishra-and-malav-soni). – Rahul May 04 '15 at 06:25
1

layer backgroundcolor is of cgcolorref type, so cant use uicolor. we need to use cgcolor or convert uicolor to cgcolor and use it.

example:

[[UIColor whiteColor] CGColor];

or

[UIColor whiteColor].CGColor;
Britto Thomas
  • 2,092
  • 1
  • 15
  • 28
  • http://stackoverflow.com/questions/30023404/issue-with-using-rgb-colors-in-ios/30026414# – Rahul May 04 '15 at 09:15