[控件] AngleGradientView
2015-05-17 22:20
267 查看
AngleGradientView
效果
说明
1. 用源码产生带环形渐变色的view
2. 可以配合maskView一起使用 (上图中的右下角图片的效果)
源码
https://github.com/YouXianMing/UI-Component-Collection
https://github.com/paiv/AngleGradientLayer
效果
说明
1. 用源码产生带环形渐变色的view
2. 可以配合maskView一起使用 (上图中的右下角图片的效果)
源码
https://github.com/YouXianMing/UI-Component-Collection
https://github.com/paiv/AngleGradientLayer
// // AngleGradientView.h // GradientLayer // // Created by YouXianMing on 15/5/15. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> typedef enum : NSUInteger { /** * 金属风格 */ GradientMetalTypeOne, GradientMetalTypeTwo, /** * 彩虹风格 */ GradientRainbow, test, } EAngleGradientType; @interface AngleGradientView : UIView /** * 返回带环形渐变颜色的view * * @param frame 尺寸 * @param colors 颜色数组(CGColor) * @param locations 颜色分割点数组(范围取值为[0, 1], 渐变递增,需要包含0与1这两个点) * * @return 创建好的带环形渐变的view */ - (instancetype)initWithFrame:(CGRect)frame withCGColors:(NSArray *)colors withLocations:(NSArray *)locations; /** * 便利构造器,便捷的创建出指定风格的渐变环形的view * * @param frame 尺寸 * @param type 指定的风格 * * @return 创建好的带环形渐变的view */ + (instancetype)gradientViewWithFrame:(CGRect)frame gradientType:(EAngleGradientType)type; @end
// // AngleGradientView.m // GradientLayer // // Created by YouXianMing on 15/5/15. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import "AngleGradientView.h" #import "AngleGradientLayer.h" @interface AngleGradientView () { AngleGradientLayer *_angleGradientLayer; } @end @implementation AngleGradientView /** * 重置layer为AngleGradientLayer */ + (Class)layerClass { return [AngleGradientLayer class]; } - (instancetype)initWithFrame:(CGRect)frame { return [self initWithFrame:frame withCGColors:nil withLocations:nil]; } - (instancetype)initWithFrame:(CGRect)frame withCGColors:(NSArray *)colors withLocations:(NSArray *)locations { self = [super initWithFrame:frame]; if (self) { _angleGradientLayer = (AngleGradientLayer *)self.layer; if (colors != nil) { _angleGradientLayer.colors = colors; _angleGradientLayer.locations = locations; } } return self; } + (instancetype)gradientViewWithFrame:(CGRect)frame gradientType:(EAngleGradientType)type { NSMutableArray *colors = nil; NSMutableArray *locations = nil; AngleGradientView *angleGradientView = nil; if (type == GradientMetalTypeOne) { colors = [[NSMutableArray alloc] initWithCapacity:16]; [colors addObject:(id)[UIColor colorWithWhite:0.65 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.9 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.75 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.35 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.75 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.9 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.75 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.35 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.55 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithWhite:0.65 alpha:1].CGColor]; } else if (type == GradientMetalTypeTwo) { colors = [[NSMutableArray alloc] initWithCapacity:16]; locations = [[NSMutableArray alloc] initWithCapacity:16]; [colors addObject:(id)[UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:1 green:1 blue:1 alpha:1].CGColor]; [locations addObject:[NSNumber numberWithInt:0]]; [locations addObject:[NSNumber numberWithInt:1]]; } else if (type == GradientRainbow) { colors = [[NSMutableArray alloc] initWithCapacity:16]; [colors addObject:(id)[UIColor colorWithRed:1 green:0 blue:0 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:1 green:1 blue:0 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:0 green:1 blue:0 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:0 green:1 blue:1 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:0 green:0 blue:1 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:1 green:0 blue:1 alpha:1].CGColor]; [colors addObject:(id)[UIColor colorWithRed:1 green:0 blue:0 alpha:1].CGColor]; } angleGradientView = [[AngleGradientView alloc] initWithFrame:frame withCGColors:colors withLocations:locations]; return angleGradientView; } @end
相关文章推荐
- AngleGradientView
- Android的常见控件(TextView、EditText、Button、Menu)使用
- 使用ASP.NET Atlas XSLTView控件用XSLT修饰并显示XML数据
- Android控件 - ViewGroup、ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams简介
- Android零基础入门第17节:Android开发第一个控件,TextView属性和方法大全
- 一步一步学android控件(之五) —— AutoCompleteTextView
- iOS开发UI篇—使用picker View控件完成一个简单的选餐应用
- 使用picker View控件完成一个简单的选餐应用
- Android RecyclerView控件的使用(一)
- Android之文本框(TextView)控件
- 安卓控件之Myautocompletetextview(有适配器)
- iPhone起步-2:iPhone常用控件、UIActionSheet、UIAlertView (转)
- 背水一战 Windows 10 (63) - 控件(WebView): 基础知识, 加载 html, http, https, ms-appx-web:///, embedded resource, ms-appdata:///, ms-local-stream://
- UITextField 文本字段控件 -- IOS (解决键盘遮住View及密文設定的问题)(实例)
- Android控件之AutoCompleteTextView、MultiAutoCompleteTextView探究
- Android Annotation(注解),简化View控件的初始化操作。
- QTableView表头填满控件,表头对齐
- IOS学习六:Date Picker, Picker View选取器控件初步
- android 自定义下拉刷新上拉加载控件(SwipeRefreshLayout + recyclerView)