iOS一个简单的设置圆角不引起性能问题的分类
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
版权声明:本文为博主原创文章,转载请附上博文链接!
转载于:https://www.cnblogs.com/sundaysgarden/p/11172706.html
iOS一个简单的设置圆角不引起性能问题的分类相关推荐
- [iOS]一个简单日历
按照需求弄的一个简单的日历,可以展开完全展示日历,也可以收回只展示已选择那一行.另外添加了选择器切换月份,还可以在列表中跨月选择切换日期. DEMO: https://download.csdn. ...
- iOS 中给view设置圆角头像(类似qq空间头像)
view有一个属性layer,通过设置cornerRadius来设置圆角的半径,view是正方形的才能保证通过调整圆角半径来形成圆形头像 [view.layer setCornerRadius:CGR ...
- iOS一个简单的点赞动画
1.首先创建一个用于点赞的按钮.在点赞按钮的点击方法里写入一下代码. 创建一个显示动画的控件. self.Image1.layer.contents = (id)[UIImageimageNamed: ...
- iOS一个简单聊天工具的实现
Top 简易的聊天工具 1.1 问题 Socket的英文原义是孔或者插座的意思,通常也称作套接字,用于描述IP地址和端口,是一个通信链的句柄,本案例使用第三方Socket编程框架AsyncSocket ...
- 【小白学PyTorch】15.TF2实现一个简单的服装分类任务
<<小白学PyTorch>> 小白学PyTorch | 14 tensorboardX可视化教程 小白学PyTorch | 13 EfficientNet详解及PyTorch实 ...
- 用nodejs搭建一个简单的服务器
使用nodejs搭建一个简单的服务器 nodejs优点:性能高(读写文件) 数据操作能力强 官网:www.nodejs.org 验证是否安装成功:cmd命令行中输入node -v 如果显示版本号表示安 ...
- iphone屏幕圆角插件_关于iOS控件设置圆角的一些个人看法(iOS 10.0.2)
写在最前面:该文章使用的机器是iPhone 6(iOS 10.0.2),得出的结果跟iOS 8和iOS 9不太一样,关于iOS 8和iOS 9的结论,在最后有. 这几天看简书上的文章,看到几篇关于控件 ...
- ipad php mysql_如何用PHP/MySQL为 iOS App 写一个简单的web服务器(译) PART1
原文:http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app 作为一个i ...
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
iOS开发UI篇-使用UItableview完成一个简单的QQ好友列表(一) 一.项目结构和plist文件 二.实现代码 1.说明: 主控制器直接继承UITableViewController // ...
最新文章
- 再学大话设计模式--附录(三)
- java验证码(采用struts2实现)转
- MySQL触发器介绍
- from + size must be less than or equal to: [10000] but was [10550]
- edX Devstack 汉化(i18n)
- SylixOS arm64 自旋锁
- equals方法的小结
- ie浏览器怎么打开html,IE浏览器无法打开网页如何解决
- u盘中毒文件为html文档,U盘中毒后文件夹被隐藏的恢复方法
- telink wiki使用简单说明
- iPhone开发阶段性总结
- ant design vue 中a-tree搜索查询
- MD2中用于随机置换的S盒是如何生成的?
- 夏季旅游度假照片展示短视频AE模板
- TensorFlow实现鸢尾花分类
- redis展示 删除 详情
- 江苏旅游职业学院计算机专业,江苏旅游职业学院有哪些专业 附好的重点专业名单...
- Unity-实现聊天气泡,即字体区域背景自适应
- 第51章 设置FLASH的读写保护及解除—零死角玩转STM32-F429系列
- CEVA:先不要着急把数据搬到云端