http://www.cocoachina.com/articles/18756

iOS设置圆角矩形和阴影效果

https://www.cnblogs.com/rayshen/p/4900336.html

////

iOS_使用UIBezierPath对象实现视图控件的立体阴影效果和半透明背景效果

https://blog.csdn.net/Sponge_CMZ/article/details/48498885

核心API

Class : UIBezierPath, CALayer
涉及的API:(API的官方详细注释详见本章结尾)

/** CALayer 的shadowPath属性. */
@property CGPathRef shadowPath

/** 创建UIBezierPath对象的相关类方法. */
+ (UIBezierPath *)bezierPathWithRect:(CGRect)rect
+ (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius
+ (UIBezierPath *)bezierPathWithOvalInRect:(CGRect)rect

功能实现

1 . 椭圆形阴影效果
效果图:


2 . 半透明背景
效果图:


Code:

1 . 椭圆形阴影效果

- (void)layoutOvalShadow
{

/** 1. 创建一个UIImageView的对象. */

UIImage *image = [UIImage imageNamed:@"1.jpg"];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(70, 200, 150, 200)];

imageView.image = image;

[self.view addSubview:imageView];

[imageView release];

/**

* @brief   2. 创建UIBezierPath的对象(椭圆形状).

* @param 椭圆形状位置和大小(参考的坐标系是要设置阴影的视图)

*/

UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(25, 230, 100, 20)];

/** 3. 设置imageView的阴影, 制造立体效果. */

imageView.layer.shadowPath = path.CGPath; /**< 指定path对象. */

imageView.layer.shadowOpacity = 0.5; /**< 阴影透明度.*/

imageView.layer.shadowRadius = 0; /**< 阴影模糊效果的半径. */

imageView.layer.shadowColor = [UIColor grayColor].CGColor; /**< 阴影颜色.*/

}

2 . 半透明背景

- (void)bezierPathBackground
{

/** 1. 创建一个UIImageView的对象, 当做背景图片. */

UIImage *image = [UIImage imageNamed:@"33.jpg"];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];

imageView.image = image;

[self.view addSubview:imageView];

[imageView release];

/** 2. 创建UILabel的对象. */

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 50, 320, 100)];

label.text = @"Our mind is a sponge, our heart is a stream.";

label.font = [UIFont systemFontOfSize:30];

label.textColor = [UIColor whiteColor];

label.backgroundColor = [UIColor clearColor];

label.numberOfLines = 0;

label.textAlignment = NSTextAlignmentCenter;

[imageView addSubview:label];

[label release];

/**

* @brief   3. 创建UIBezierPath的对象(圆角效果的矩形)

* @param 1: 矩形的位置和大小(参考的坐标系是要设置阴影的视图)

* @param 2: 圆角的半径

*/

UIBezierPath *backgroundPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 320, 100) cornerRadius:5];

/** 4. 设置label的阴影, 制造半透明背景效果. */

label.layer.shadowPath = backgroundPath.CGPath;

label.layer.shadowOpacity = 0.4;

label.layer.shadowRadius = 0;

label.layer.shadowColor = [UIColor grayColor].CGColor;

}

核心API
功能实现
Code
API 官方注释
API 官方注释

/**
* @brief Creates and returns a new UIBezierPath object initialized with a rectangular path.
* @param <rect> The rectangle describing the path to create.
* @return A new path object with the rectangular path.
*/
+ (UIBezierPath *)bezierPathWithRect:(CGRect)rect

/**
* @brief Creates and returns a new UIBezierPath object initialized with an oval path inscribed in the specified rectangle
* @ param <rect> The rectangle in which to inscribe an oval.
*/
+ (UIBezierPath *)bezierPathWithOvalInRect:(CGRect)rect

/**
* @brief Creates and returns a new UIBezierPath object initialized with a rounded rectangular path.
* @param <rect> The rectangle that defines the basic shape of the path
* @param <cornerRadius> The radius of each corner oval. A value of 0 results in a rectangle without rounded corners. Values larger than half the rectangle’s width or height are clamped appropriately to half the width or height.
* @return A new path object with the rounded rectangular path.
*/
+ (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius
---------------------
作者:Sponge_CMZ
来源:CSDN
原文:https://blog.csdn.net/Sponge_CMZ/article/details/48498885
版权声明:本文为博主原创文章,转载请附上博文链接!

iOS一个简单的设置圆角不引起性能问题的分类的更多相关文章

  1. iOS8 超简单的设置圆角按钮 ImageView等UIView

    button.layer.cornerRadius = // 这个值根据你想要的效果可以更改 button.clipsToBounds = true 这种方法不止可以设置按钮,UIView应该都可以设 ...

  2. 一个简单的创建圆角图像的UIImage扩展实现

    - (UIImage *)roundedCornerImageWithCornerRadius:(CGFloat)cornerRadius { CGFloat w = self.size.width; ...

  3. iOS 一个简单的单例

    比如我有一个Singleton的类(DemoStatusManage),他有一个实例方法currentStatus会返回一个1-100的随机数. @interface DemoStatusManage ...

  4. iOS - 一个简单的带标题的图标的实现

    代码不复杂,直接上代码: ImageViewButton.h // // ImageViewButton.h// // 带有图片.底部标题或者顶部的按钮 // // #import <UIKit ...

  5. 【小白学PyTorch】15 TF2实现一个简单的服装分类任务

    [新闻]:机器学习炼丹术的粉丝的人工智能交流群已经建立,目前有目标检测.医学图像.时间序列等多个目标为技术学习的分群和水群唠嗑的总群,欢迎大家加炼丹兄为好友,加入炼丹协会.微信:cyx64501661 ...

  6. 用nodejs搭建一个简单的服务器

    使用nodejs搭建一个简单的服务器 nodejs优点:性能高(读写文件) 数据操作能力强 官网:www.nodejs.org 验证是否安装成功:cmd命令行中输入node -v 如果显示版本号表示安 ...

  7. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  8. iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序

    iOS开发UI篇—使用嵌套模型完成的一个简单汽车图标展示程序 一.plist文件和项目结构图 说明:这是一个嵌套模型的示例 二.代码示例: YYcarsgroup.h文件代码: // // YYcar ...

  9. iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局

    iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...

随机推荐

  1. 思科ISE配置专题–ISE部署方式

    ISE部署方式有三种: 1.Standalong Deployment 所谓Standalong部署就是只有一台ISE,所有的组件都安装在这一台上面.一台ISE装好的时候默认是“Standalong” ...

  2. Codeforces Round #618 (Div. 1)A(观察规律)

    实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...

  3. ftrace使用

    前段时间遇到个问题,有个后继音频数据处理线程调度不及时导致音频输出延迟,音视频不同步. 因此从系统上入手,采用ftrace进行debug,来看有哪些线程会去抢占音频数据处理线程. ftrace 提供了 ...

  4. alsa driver--card

    1.创建声卡 snd_card是对声卡硬件抽象出来的结构体,几乎所有与声音相关的逻辑设备都是在snd_card的管理之下,声卡驱动的第一个动作通常就是创建一个snd_card结构体. 我们可以通过调用 ...

  5. Java经典面试笔试题及答案

    1.什么是对象序列化,为什么要使用? 所谓对象序列化就是把一个对象以二进制流的方式保存到硬盘上.好处:方便远程调用. 2.值传递与引用传递的区别? 所谓值传递就是把一个对象的值传给一个新的变量,但是系 ...

  6. 如何安装和使用Maven

    今天我们来学习一下如何安装Maven,把步骤分享给大家,希望能对大家有帮助! 我的博客地址:https://www.cnblogs.com/themysteryofhackers/p/11996550 ...

  7. NET com组件注册

    1.签名 右击项目->属性->[签名]标签, 选中[为程序集签名]–>[选择强名称密钥文件]–>[新建],输入你的密钥名称,去掉[使用密码保护密钥文件] 最重要的签名,并且注册 ...

  8. Azure虚拟机网站部署 防火墙设置

    唯一需要注意的是当你的网站设置的端口不是默认的80的时候,需要在防火墙那里将你新设置的端口设置为allow 先要到云的后台设置  “入站安全规则”--> 将你的网站端口设置为Allow 1.通过 ...

  9. MyBatis XML常用配置

    1.属性(properties) 可外部配置且可动态替换的,既可以在典型的 Java 属性文件中配置,亦可通过 properties 元素的子元素来传递. 可以外部定义好properties文件通过 ...

  10. 2000G电脑大型单机游戏合集

    激活码 游戏名称(ctrl+F查找) 下载链接005875 艾迪芬奇的记忆 游戏下载链接http://pan.baidu.com/s/1t2PYRAj546_1AcOB-khJZg554158 暗影: ...