Is there a way to set the sides of the border of a UIView to one color and leave the top and the bottom another?
Ios – UIView set only side borders
cocoa-touchiosobjective cuiview
Related Topic
- Ios – Allowing interaction with a UIView under another UIView
- Ios – How to set iPhone UIView z index
- Ios – UIView with rounded corners and drop shadow
- Ios – Loaded nib but the ‘view’ outlet was not set
- Ios – Passing data between view controllers
- Ios – How to set cornerRadius for only top-left and top-right corner of a UIView
- Ios – How to animate constraint changes
- Ios – How to add a border just on the top side of a UIView
Best Answer
Nope—CALayer borders don’t support that behavior. The easiest way to accomplish what you want is adding an n-point-wide opaque subview with your desired border color as its background color on each side of your view.
Example:
Note that this won’t quite match the behavior of CALayer borders—the left and right border views will always be inside the boundaries of their superview.