Is it possible to add a border just on top of a UIView, if so, how please?
Swift5:
We will write a separate method to add borders to this view. To add borders to this view we will create two layers with the desired thickness. We will set the frame of these two layers to the top and bottom of the view. We will set the desired background color of the borders on these layers and add these layers as subLayers to the view.
func addTopBorders() {
let thickness: CGFloat = 1.0
let topBorder = CALayer()
topBorder.frame = CGRect(x: 0.0, y: 0.0, width:
self.down_view_outlet.frame.size.width, height: thickness)
topBorder.backgroundColor = UIColor.white.cgColor
down_view_outlet.layer.addSublayer(topBorder)
}
remus' answer in Obj-C:
CALayer *topBorder = [CALayer new];
topBorder.frame = CGRectMake(0.0, 0.0, self.frame.size.width, 3.0);
topBorder.backgroundColor = [UIColor redColor].CGColor;
[myView.layer addSublayer:topBorder];