AKSimpleColorPicker 版本 0.1.0

AKSimpleColorPicker 版本 0.1.0

Alc77 维护。



  • 作者:
  • Alc77

AKSimpleColorPicker

language  CI Status  Version  License  Platform 

为什么选择 AKSimpleColorPicker?

它是一个基于 OpenGL 的简单类似 Photoshop 的颜色选择器。

Objective-C 

示例

要运行示例项目,请先克隆仓库,然后从 AKSimpleColorPicker/Example 目录运行 AKSimpleColorPicker.xcworkspace

需求

AKSimpleColorPicker在iOS 9.0及以上版本上运行,并兼容ARC项目。它依赖于以下Apple框架:

  • Foundation.framework
  • UIKit.framework
  • GLKit.framework

安装

手动安装

您可以直接将源文件添加到项目中。

  1. 从GitHub下载最新的zip文件,或在您选择的目录中克隆源文件。
  2. 在Xcode中打开您的项目,然后将文件夹AKSimpleColorPicker/AKSimpleColorPicker/Classes拖放到项目中(使用“Product Navigator视图”)。如果在项目外提取了代码存档,请确保选择复制项。
  3. 在前视图中使用AKSimpleColorPicker时,请使用#import "AKSimpleColorPicker.h"将其包含在内。

使用CocoaPods

CocoaPods是将AKSimpleColorPicker添加到项目的推荐方法。

  1. 在Podfile中添加AKSimpleColorPicker的pod项pod 'AKSimpleColorPicker'
  2. 通过运行pod install来安装pod(s)。
  3. 使用AKSimpleColorPicker时,请在视图控制器中包含#import <AKSimpleColorPicker/AKSimpleColorPicker.h>

使用方法

  1. 在需要的视图控制器中包含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];
}
  1. viewDidLoad中订阅colorChanged通知

Objective-c:

- (void)viewDidLoad {
	[super viewDidLoad];
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeColor:) name:@"colorChanged" object:nil];
	
	// add your settings
}
  1. 创建通知处理器并从通知字典中接收颜色

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文件。