Reputation: 534
I am trying to add border line between 2 UIView, as i researched, the following code can add 4 borders.
CGFloat borderWidth = 5.0f;
self.imgview.frame = CGRectInset(self.imgview. frame, -borderWidth, -borderWidth);
self.imgview. layer.borderColor = [UIColor blueColor].CGColor;
self.imgview. layer.borderWidth = borderWidth;
However, i just need to add one border, any advice? Thanks in advance.
Upvotes: 0
Views: 957
Reputation: 46
If you want to set these borders programmatically, you can use the following snippet of code
+(void)SetImageViewBottomBorder :(UIImageView *)imageView{
CALayer *border = [CALayer layer];
CGFloat borderWidth = 1;
border.borderColor = [[self colorWithHexString:@"9B9B9B"] CGColor];
border.frame = CGRectMake(0, imageView.frame.size.height - borderWidth, imageView.frame.size.width, imageView.frame.size.height);
border.borderWidth = borderWidth;
[imageView.layer addSublayer:border];
imageView.userInteractionEnabled = YES;
imageView.layer.masksToBounds = YES;
}
you can replace the UIImageView with UIView and it will be working like a charm.
Upvotes: 0
Reputation: 56
You can add one One more UIView (BorderView) between two UIView (View1 and View2). Give the border view appropriate width and background color.
Upvotes: 1