在UIImageView周围设置边框 [英] Set border around UIImageView

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

问题描述

我想在 UIImageView 上应用两种类型的边框:

I want to apply two types of border on a UIImageView:


  1. 一个是 UIImageView 图层的边框。

  2. 其次是 UIImageView 图层周围的边框。

  1. One is the border on the layer of the UIImageView.
  2. Second is the border around the layer of the UIImageView.

我该怎么做?

推荐答案

试试

#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屋!

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