iOS渐变和自定义圆角的实现
2016-08-20 00:19
197 查看
软件工程师在传统观念里可能就是写代码,完成项目需求。但对我而言,作为一名互联网从业者,不应该只是掌握一门技能,在平时的工作中也让自己充当产品经理,UI设计等角色,毕竟牛逼的用户体验是每个人喜欢的,不妨放开思路,尝试着做些不一样的东西。
在一些项目中,可能希望有这样的效果,某个view显示的是渐变风格,并且可能不是规则的矩形或者圆形,如何实现这种特效,下面小编给大家介绍一下这个方法,希望能帮到大家。
1.实现自定义圆角
其中,UIRectCornerTopRight | UIRectCornerBottomRight表示右上右下为圆角,CGSizeMake(10,10)表示圆角度数为10,可以根据项目需求更改这两个值。
2.实现渐变
其中,gradientLayer.colors表示设定渐变的颜色数组,可以自定义;gradientLayer.startPoint ,gradientLayer.endPoint分别设定渐变的起始和结束位置,范围为0到1。
如果您对我的文章感兴趣,请关注我的公众号,希望在互联网的道路上我们并肩前行。
在一些项目中,可能希望有这样的效果,某个view显示的是渐变风格,并且可能不是规则的矩形或者圆形,如何实现这种特效,下面小编给大家介绍一下这个方法,希望能帮到大家。
1.实现自定义圆角
-(void)setCustomCorners:(UIView *)view { <span style="white-space:pre"> </span>UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(10,10)]; <span style="white-space:pre"> </span>CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; <span style="white-space:pre"> </span>maskLayer.frame = view.bounds; <span style="white-space:pre"> </span>maskLayer.path = maskPath.CGPath; <span style="white-space:pre"> </span>view.layer.mask = maskLayer; }
其中,UIRectCornerTopRight | UIRectCornerBottomRight表示右上右下为圆角,CGSizeMake(10,10)表示圆角度数为10,可以根据项目需求更改这两个值。
2.实现渐变
-(void)setCustomGradientLayer:(UIView *)view { <span style="white-space:pre"> </span>CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init]; <span style="white-space:pre"> </span>gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:73.0f/255.0f green:148.0f/255.0f blue:230.0f/255.0f alpha:0.5].CGColor,(__bridge id)[UIColor blueColor].CGColor]; <span style="white-space:pre"> </span>gradientLayer.startPoint = CGPointMake(0.5, 0); <span style="white-space:pre"> </span>gradientLayer.endPoint = CGPointMake(0.5, 1); <span style="white-space:pre"> </span>gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.colorBackgroundView.frame), CGRectGetHeight(self.colorBackgroundView.frame)); <span style="white-space:pre"> </span>[view.layer addSublayer:gradientLayer]; }
其中,gradientLayer.colors表示设定渐变的颜色数组,可以自定义;gradientLayer.startPoint ,gradientLayer.endPoint分别设定渐变的起始和结束位置,范围为0到1。
如果您对我的文章感兴趣,请关注我的公众号,希望在互联网的道路上我们并肩前行。
相关文章推荐
- iOS swift-自定义转场动画_实现modal控制器显示与消失时的透明度渐变
- [iOS]自定义 TableViewCell 实现圆角/渐变色 TableView
- 如何创建[圆角、边框色彩渐变、边框宽度自定义]窗体
- CSS技巧 — 不使用图片实现圆角、阴影、渐变等功能
- 自定义的iOS的滚轮选择器,附带农历选择器实现代码
- Agg图形库学习笔记-实现任意方向圆角渐变矩形
- 主题:转:shape 渐变!描边!圆角!漂亮的自定义背景
- 如何创建[圆角、边框色彩渐变、边框宽度自定义]窗体
- android自定义listview实现圆角
- android 使用java编程实现圆角渐变矩形的绘制
- CSS技巧 — 不使用图片实现圆角、阴影、渐变等功能【转】
- [iPhone中级] IOS中实现自定义UICombox
- CSS技巧 — 不使用图片实现圆角、阴影、渐变等功能
- 自定义的iOS的滚轮选择器,附带农历选择器实现
- shape 渐变!描边!圆角!漂亮的自定义背景
- 【IOS】自定义UIAlertView样式,实现可替换背景和按钮
- CSS技巧 — 不使用图片实现圆角、阴影、渐变等功能
- [iOS]实现了一套自定义动画库
- 自定义的iOS的滚轮选择器,附带农历选择器实现
- ios学习--iPhone遮盖系统栏,实现自定义效果的状态栏