【问题标题】:Shrink UIImage in bordered UIImageView在带边框的 UIImageView 中缩小 UIImage
【发布时间】:2013-06-19 14:00:50
【问题描述】:

我在 UIImageView 上画了一个边框...

[[albumImage layer] setBorderColor:[[UIColor whiteColor] CGColor]];
[[albumImage layer] setBorderWidth:10.0];

但是那些额外的 10 个像素被绘制在 内部 图像视图中。我的部分图像被切断了!我想要:

  • 将 UIImage 缩小 0.96 倍,使其适合边框内.. 或
  • 在 IB 中将 UIImageView 每边缩小 10 个像素,然后在图像视图之外绘制边框

使用contentModetransformcontentScaleFactor 并不是正确的解决方案。最后两个缩放整个图像视图(包括边框)。内容模式只是改变图像在视图中的适应方式(在我的例子中已经设置好了)

【问题讨论】:

    标签: ios objective-c uiimageview


    【解决方案1】:

    我会将图像视图添加到容器视图中并在容器视图上绘制边框。如果你在 XIB 中做容器,那么你可以在那里设置大小。如果您在代码中执行此操作,请将图像视图框架设置为:

    imageView.frame = CGRectInset(containerView.bounds, 10, 10);
    

    【讨论】:

      猜你喜欢
      • 2018-12-01
      • 2010-09-28
      • 2013-03-05
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多