1

In iOS, how can I change layer.border.top color? If I change self.layer.borderColor, all the side change. But If I only want to change one side, and keep other three sides as is, what should I do?

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
seguedestination
  • 419
  • 4
  • 19

1 Answers1

0

how about adding a new layer?

yourView.clipsToBounds = YES;

CALayer *topBorder = [CALayer layer];
topBorder.borderColor = [UIColor redColor].CGColor;
topBorder.borderWidth = 1;
topBorder.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), 2);    
[yourView.layer addSublayer:topBorder];

replace yourView with whatever view is contained in your view controller that you want to add the border to.

Also, this related answer might help you out a bit.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215