-1

Here i am trying to set the multiple colors to the user profile icon border.

                CAGradientLayer *layer2 = [CAGradientLayer layer];
                NSArray *colors = [NSArray arrayWithObjects:
                                   (id)[UIColor whiteColor].CGColor,
                                   (id)[UIColor redColor].CGColor,
                                   nil];

Below line is giving me error i want set it's border color by adding color from the array but it is giving me error.How can i pass array of colors to setBorderColor: method.

                [layer2 setBorderColor:colors];

                //below code is working fine
                [layer2 setFrame:cell.userIcon.layer.frame];
                [cell.userIcon.layer insertSublayer:layer2 atIndex:0];
                cell.userIcon.clipsToBounds = YES; // Important!
vicky
  • 253
  • 2
  • 14
  • 1
    Check out some other question that already solved this like [this](http://stackoverflow.com/questions/15193993/how-to-make-a-gradient-border-of-uiview) or [this](http://stackoverflow.com/questions/34528782/how-to-make-calayer-border-with-gradient-or-multiple-colors) – Tj3n Oct 28 '16 at 08:14
  • i have already checked them and there is no passing of array in that only a single color @Tj3n – vicky Oct 28 '16 at 08:15
  • And? Did you follow the answer in there? – Tj3n Oct 28 '16 at 08:17
  • yes they are passing a single color to the setBorderColor: method not an array @Tj3n – vicky Oct 28 '16 at 08:18
  • What makes you think you can pass an array of colors to a property that wants a single color? There's no way to achieve what you're trying without using another method. – Cyrille Oct 28 '16 at 08:22
  • so can you suggest me anything which will help me to achieve waht i want to @Cyrille – vicky Oct 28 '16 at 08:23
  • 1
    @Tj3n already suggested links for you in his first comment. – Cyrille Oct 28 '16 at 08:24
  • but those links are no longer useful to me as they pass a single color to the method i want other method or any other solution to my problem .@Cyrille – vicky Oct 28 '16 at 08:27
  • It's not single color, its gradient, you can pass just any color you want in there – Tj3n Oct 28 '16 at 09:56

1 Answers1

0

You are confusing the colors and borderColor property. colors property can be set for the whole layer with multiple colors, however, borderColor does not accept an array of CGColor.

Here is a screenshot from the API documentation:

enter image description here

So, setBorderColor only accepts CGColor, but you are assigning an NSArray instead. borderColor property can ONLY be set by a single CGColor.

However, if you would like to add a single CGColor to the border color from an array, you could do the following. Just store UIColor in the array.

NSArray *colors = [NSArray arrayWithObjects:
                   [UIColor whiteColor],
                   [UIColor redColor],
                   nil];

And when you are trying to set to a layer, do the following:

[layer2 setBorderColor:((UIColor*)colors.firstObject).CGColor];

You can replace colors.firstObject to the colors[0] or colors[1], depending on which color you need.

dirtydanee
  • 6,081
  • 2
  • 27
  • 43
  • i want both the colors in the same border thats why i am using gradient, i am not going to use one by one from array i want both of them at a time. – vicky Oct 28 '16 at 08:29
  • thanks for the help but i want two colors in border at the same time. – vicky Oct 28 '16 at 08:41