NO, CALayer borders do not support this behavior.
But you can try an alternative method, if you need to implement this, try adding an opaque n-point-wide sub-layer with the desired border color as the background color on each side of your main view.
Add this code:
CGSize mainViewSize = theView.bounds.size; CGFloat borderWidth = 2; UIColor *borderColor = [UIColor redColor]; CGFloat heightfromTop = 25; UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, heightfromTop borderWidth, mainViewSize.height-heightfromTop)]; UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(mainViewSize.width - borderWidth, heightfromTop, borderWidth, mainViewSize.height-heightfromTop)]; leftView.opaque = YES; rightView.opaque = YES; leftView.backgroundColor = borderColor; rightView.backgroundColor = borderColor; [mainView addSubview:leftView]; [mainView addSubview:rightView];
This will add borders for both sides only. Repeat the same idea for the top and bottom.
NB : heightfromTop is the height of the top where you donβt want the border view present, you can change it to suit your needs.
source share