在UIImageView周围设置边框 [英] Set border around UIImageView
本文介绍了在UIImageView周围设置边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 UIImageView
上应用两种类型的边框:
I want to apply two types of border on a UIImageView
:
- 一个是
UIImageView
的图层
的边框。 - 其次是
UIImageView
的图层
周围的边框。
- One is the border on the
layer
of theUIImageView
. - Second is the border around the
layer
of theUIImageView
.
我该怎么做?
推荐答案
试试
#define kBorderWidth 3.0
#define kCornerRadius 8.0
CALayer *borderLayer = [CALayer layer];
CGRect borderFrame = CGRectMake(0, 0, (imageView.frame.size.width), (imageView.frame.size.height));
[borderLayer setBackgroundColor:[[UIColor clearColor] CGColor]];
[borderLayer setFrame:borderFrame];
[borderLayer setCornerRadius:kCornerRadius];
[borderLayer setBorderWidth:kBorderWidth];
[borderLayer setBorderColor:[[UIColor redColor] CGColor]];
[imageView.layer addSublayer:borderLayer];
不要忘记导入QuartzCore / QuartzCore.h
And don't forget to import QuartzCore/QuartzCore.h
此示例将在图层上绘制一个边框,但稍微更改它的边框以在图层周围创建边框。
This example will draw a boarder on the layer, but change it's frame slightly to make the border around the layer.
这篇关于在UIImageView周围设置边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文