使用 8 个图像在 UIImageView 周围创建边框

Create a border around UIImageView using 8 images(使用 8 个图像在 UIImageView 周围创建边框)

本文介绍了使用 8 个图像在 UIImageView 周围创建边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了 8 个图像,每个角 4 个图像,UIImageView 的每个边 4 个图像.现在,我到底如何让它们绕过" view 以便它们形成一个漂亮的、可拉伸的边框,就像这样(白线是我尝试实现的边框):

关于如何基于 8 个预设图像实现 view 的边框有什么想法吗?

我不想绘制边框,我想使用我的 8 张图片!

解决方案

这不是你真正想要的,但这是最接近你想要做的解决方案.

您应该将 8 张图片组合成一张图片,然后使用 借用"的拉伸与平铺图像)

I have 8 images I made, 4 images for each of the corners, and 4 images for each of the sides of UIImageView. Now, how on Earth do I make them 'come around' the view so they form a nice-looking, stretchable border, something like this (the white line is the border I try to implement):

Any ideas on how do you implement a border of a view based on 8 preset images?

EDIT: I don't want to draw the border, I want to use my 8 images!

解决方案

It is not really what you are asking for but this is the solution closest to what you are trying to do.

You should take your 8 images and combine them into one single image and then make a resizable image out of that using resizableImageWithCapInsets:resizingMode:.

The first arguments lets you specify the top, left, bottom and right inset (i.e. the sizes of your images).

The second argument determines if the areas are stretched or tiled.

Stretched

Tiled

So to use it you would do something similar to

UIImage *myFullImage = [UIImage imageNamed:@"nameOfTheCombinedImage"];
UIImage *resizableImage = 
[myFullImage resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)resizingMode:UIImageResizingModeTile];

(stretched vs tiles images "borrowed" from here)

这篇关于使用 8 个图像在 UIImageView 周围创建边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 8 个图像在 UIImageView 周围创建边框

基础教程推荐