iOS  颜色选择器(比较两种)

一种:iOS 颜色选择器:HRColorPicker 

https://github.com/hayashi311/Color-Picker-for-iOS/


封装后对外属性: colorInfoView(色值显示)、 colorMapView(色板控制)、 brightnessSlider(颜色深度控制条)

如果不改变UI布局,使用非常简单,几行代码就可以搞定:
#import "HRColorPickerView.h"

@interface HRSampleColorPickerViewController () {
   
id < HRColorPickerViewControllerDelegate > __weak delegate;
}

@property ( nonatomic , weak ) IBOutlet HRColorPickerView *colorPickerView;

@end

@implementation HRSampleColorPickerViewController {
   
UIColor *_color;
}

@synthesize delegate;

- (
id )initWithCoder:( NSCoder *)coder {
   
self = [ super initWithCoder :coder];
   
if ( self ) {
    }
   
return self ;
}

- (
void )viewDidLoad {
    [
super viewDidLoad ];
   
self . colorPickerView . color = _color ;
    [
self . colorPickerView addTarget : self
                            
action : @selector (colorDidChange:)
                  
forControlEvents : UIControlEventValueChanged ];
}

- (
void )viewWillDisappear:( BOOL )animated {
    [
super viewWillDisappear :animated];
   
if ( self . delegate ) {
        [
self . delegate setSelectedColor : self . color ];
    }
}

- (
void )colorDidChange:( HRColorPickerView *)colorPickerView {
   
_color = colorPickerView. color ;
}



一种:iOS 颜色选择器组件:MSColorPicker
(可以使用cocoaPods,pod "MSColorPicker",) 

这种方法是将颜色选择页面进行整体封装,使用时跳转到封装好的页面就可以,如果想要获取选中的颜色,对外实现协议就可以获取,这种算是进行了深层的封装,所有东西在内部处理,外部只能接收。
用起来更是简单:
MSColorSelectionViewController *colorSelectionController = [[ MSColorSelectionViewController alloc ] init ];
   
UINavigationController *navCtrl = [[ UINavigationController alloc ] initWithRootViewController :colorSelectionController];

    navCtrl.
modalPresentationStyle = UIModalPresentationPopover ;
    navCtrl.
popoverPresentationController . delegate = self ;
    navCtrl.
popoverPresentationController . sourceView = button;
    navCtrl.
popoverPresentationController . sourceRect = button. bounds ;
    navCtrl.
preferredContentSize = [colorSelectionController. view systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];

    colorSelectionController.
delegate = self ;
    colorSelectionController.color = self.view.backgroundColor;

 [ self presentViewController :navCtrl animated : YES completion : nil ];

我觉得两种都可以,实现的都不错,看个人喜好和界面要求。



  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值