UIImageView的外部边界



我知道我可以使用下面的代码创建边界。

[[myImageView layer] setBorderWidth:2.0f];
[[myImageView layer] setBorderColor:[UIColor greenColor].CGColor];

然而,这在图像内部绘制边框。

我所看到的是在ImageView外部绘制边框。

注意:

我在网上搜索并在下面找到了这个

  1. 可以通过使用另一个有边框的图像来完成

  2. 可以通过绘制另一个比当前图像稍大的视图来完成

有没有一种快速的方法(尤其是在内置的iOS中),我可以在UIImageView之外绘制边框?有什么看法吗

为什么不尝试使用imageview的边框?

  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;

iOS中没有内置的快速通道,您可以在图像层上设置空白。

如果我是你,我会开发一个继承自UIView的新类(例如UIImageWithBorderView),其中包括一个UIImageView,并使"UIImageWithBorderView"比UIImageView大(并考虑不要用UIView父级自动重设UIImageView的大小,否则你的UIImageView将被拉伸,并防止UIImageWithBolderView小于UIImageView框架),然后将边框添加到"UIImageWithBorderView"中。这样,你的UIImageView将完好无损,你将有一个特定的、可重复使用的堆肥来满足你的需求。

希望它能有所帮助!

最新更新