How to give #3f51b5 color code programmatically for shadow color in ios

355 views Asked by At

I want to make shadow color with #3f51b5.

How can I do that. hope your help. this type cannot use to do that.

cell.layer.shadowColor = [UIColor purpleColor].CGColor;
2

There are 2 answers

4
Sumit Oberoi On

after setting the color give shadow radius,offset and opacity, convert the color to rgba and use this

  cell.layer.shadowColor = [UIColor colorWithRed:0.2471 green:0.3176 blue:0.7098 alpha:1.0].CGColor;
  cell.layer.shadowRadius=10;
  cell.layer.shadowOffset=CGSizeMake(1, 1);
  cell.layer.shadowOpacity=1;

if you want to use hex color only use this How can I create a UIColor from a hex string?

0
Tejas Ardeshna On

you need to set shadow first

cell.layer.shadowRadius=8;
cell.layer.shadowOffset=CGSizeMake(-1, -1);// this make top left shadow
cell.layer.shadowOpacity=1;
cell.layer.shadowColor = [UIColor colorWithRed:0.2471 green:0.3176 blue:0.7098 alpha:1.0].CGColor;