我正在尝试在2个UIView之间添加边界线,正如我研究的那样,以下代码可以添加4个边框。
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;
但是,我只需要添加一个边框,任何建议?提前谢谢。
答案 0 :(得分:1)
答案 1 :(得分:0)
如果要以编程方式设置这些边框,可以使用以下代码段
+(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;
}
你可以用UIView替换UIImageView,它就像魅力一样。