使用8张图片在UIImageView周围创建边框 [英] Create a border around UIImageView using 8 images

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

问题描述

我有8张图片,每个角落有4张图片, UIImageView 每侧各有4张图片。现在,我如何在地球上让他们来到视图,所以他们形成一个漂亮的,可伸缩的边框,这样的东西(白线是边界尝试实现):



有关如何根据8张预设图片实现视图的边框的任何想法?



编辑:我不想绘制边框,我想使用我的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周围创建边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆