1

I know I can change a border's object with

item.layer.cornerRadius = floatValue;
item.layer.borderWidth = intValue;
item.layer.borderColor = colorValue;

But how can I only change top, left and right borders ?

Thank you for your advices.

Rob
  • 15,732
  • 22
  • 69
  • 107

2 Answers2

3

I don't think you can do that directly.

There are a couple of responses to this question that might help, including one that links to some open source code that solves the problem.

Community
  • 1
  • 1
Amy Worrall
  • 16,250
  • 3
  • 42
  • 65
2

You could use another layer to mask away the corners that you don't want to see. This has the downside that you:

  • can't have a shadow
  • can't have another mask (if you don't do them together)
  • will loose half the border width since the border is stroked on the center of your border

If that is okay with you, here is a sample code that should get you started

CGFloat borderWidth = 4.0;
[[myView layer] setBorderWidth:borderWidth];

CALayer *mask = [CALayer layer];
// The mask needs to be filled to mask
[mask setBackgroundColor:[[UIColor blackColor] CGColor]];
// Make the masks frame smaller in height
CGRect maskFrame = CGRectInset([myView bounds], 0, borderWidth);
// Move the maskFrame to the top
maskFrame.origin.y = 0;
[mask setFrame:maskFrame];
[[myView layer] setMask:mask];
David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205