AKSimpleColorPicker
为什么选择 AKSimpleColorPicker?
它是一个基于 OpenGL 的简单类似 Photoshop 的颜色选择器。
示例
要运行示例项目,请先克隆仓库,然后从 AKSimpleColorPicker/Example
目录运行 AKSimpleColorPicker.xcworkspace
。
需求
AKSimpleColorPicker在iOS 9.0及以上版本上运行,并兼容ARC项目。它依赖于以下Apple框架:
- Foundation.framework
- UIKit.framework
- GLKit.framework
安装
手动安装
您可以直接将源文件添加到项目中。
- 从GitHub下载最新的zip文件,或在您选择的目录中克隆源文件。
- 在Xcode中打开您的项目,然后将文件夹
AKSimpleColorPicker/AKSimpleColorPicker/Classes
拖放到项目中(使用“Product Navigator视图”)。如果在项目外提取了代码存档,请确保选择复制项。 - 在前视图中使用AKSimpleColorPicker时,请使用
#import "AKSimpleColorPicker.h"
将其包含在内。
使用CocoaPods
CocoaPods是将AKSimpleColorPicker添加到项目的推荐方法。
- 在Podfile中添加AKSimpleColorPicker的pod项
pod 'AKSimpleColorPicker'
- 通过运行
pod install
来安装pod(s)。 - 使用AKSimpleColorPicker时,请在视图控制器中包含
#import <AKSimpleColorPicker/AKSimpleColorPicker.h>
。
使用方法
- 在需要的视图控制器中包含AKSimpleColorPicker后创建包含选择视图的
AKColorPickerViewController
实例。假设您在某个按钮处理程序中创建它
Objective-c:
- (IBAction)changeColorPressed:(UIButton*)sender {
AKColorPickerViewController *changeColorVC = [[AKColorPickerViewController alloc] init];
changeColorVC.glRoughViewRelativeHeight = 0.1; // not mandratory parameter
changeColorVC.glPreciseViewRelativeHeight = 0.4; // not mandratory parameter
changeColorVC.providesPresentationContextTransitionStyle = YES;
changeColorVC.definesPresentationContext = YES;
changeColorVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:changeColorVC animated:YES completion:nil];
}
- 在
viewDidLoad
中订阅colorChanged
通知
Objective-c:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeColor:) name:@"colorChanged" object:nil];
// add your settings
}
- 创建通知处理器并从通知字典中接收颜色
Objective-c:
- (void)didChangeColor:(NSNotification*)n {
UIColor *color = n.userInfo[@"color"];
// Do whatever you want with the received color.
}
自定义
颜色选择器有两个自定义参数
Objective-c:
@property (nonatomic) CGFloat glRoughViewRelativeHeight;
@property (nonatomic) CGFloat glPreciseViewRelativeHeight;
它们都影响相应选择器的高度。每个的高度不能小于0.1屏幕高度,它们的总高度不能超过屏幕高度的0.75。您可以在创建AKColorPickerViewController之后调整它们,如第1段所述。
许可证
AKSimpleColorPicker在MIT许可证下可用。更多信息请参阅LICENSE文件。