ios - 在带边框的 UIImageView 中缩小 UIImage

标签 ios objective-c uiimageview

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

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

但是那些额外的 10 个像素是在 ImageView 中绘制的。我的部分图像被切断了!我想要:
  • 将 UIImage 缩小 0.96 倍,使其适合边框内.. 或
  • 在 IB 中将 UIImageView 每边缩小 10 个像素,然后在 ImageView 外绘制边框

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

    最佳答案

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

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

    关于ios - 在带边框的 UIImageView 中缩小 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17193271/

    相关文章:

    ios - UIImageView 保持宽高比,但适合宽度

    ios - iOS7 中的滑动手势控制问题

    ios - 在 iOS 中,如何禁用粘贴到 UITextfield 或其他输入字段中?

    iphone - 我应该使用 NSUserDefaults 还是 plist 来存储数据?

    iphone - 如何在标签上显示当前时间?

    IOS 无法在运行时重新定位 UIImageView

    iphone - 导入指令不允许访问该类

    ios - 这个多态性的例子是错误的吗?

    ios - 如何重新加载 UITableView 数据避免卡住

    ios - 如何在 Swift 中为 UIImages 创建闪烁的指针效果