1 Star 1 Fork 0

wuxie8 / 色彩滑块

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
EOColorView.m 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
wuxie8 提交于 2018-08-08 16:45 . 直接导入项目中使用
//
// EOColorView.m 颜色color
// EastOffice2.0
//
// Created by YLY on 2017/11/30.
// Copyright © 2017年 EO. All rights reserved.
//
#import "EOColorView.h"
@interface EOColorView ()
@property (strong, nonatomic) NSArray *colorStringArr;
@property (strong, nonatomic) NSString *colorString;
@property (strong, nonatomic) UIImageView *showView;
@property (strong, nonatomic) UIView *showColor;
@end
@implementation EOColorView
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"%g, %g", point.x, point.y);
int index = floor(point.x / kSCRATIO(15));
if (index >= 0 && index < self.colorStringArr.count) {
NSString *colorString = self.colorStringArr[index];
!self.colorBlock ? : self.colorBlock(colorString);
if (!self.showView) {
self.showView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fangda1"]];
self.showView.frame = CGRectZero;
self.showColor = [[UIView alloc] init];
self.showColor.frame = CGRectZero;
}
[self addSubview:self.showView];
[self.showView addSubview:self.showColor];
self.showView.frame = CGRectMake(point.x - kSCRATIO(17.5), kSCRATIO(-37.5), kSCRATIO(35), kSCRATIO(65));
self.showColor.frame = CGRectMake(kSCRATIO(2), kSCRATIO(2), kSCRATIO(30), kSCRATIO(28));
self.showColor.backgroundColor = [UIColor colorFromHexCode:colorString];
}
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"%g, %g", point.x, point.y);
int index = floor(point.x / kSCRATIO(15));
if (index >= 0 && index < self.colorStringArr.count) {
NSString *colorString = self.colorStringArr[index];
!self.colorBlock ? : self.colorBlock(colorString);
self.showView.frame = CGRectMake(point.x - kSCRATIO(17.5), kSCRATIO(-37.5), kSCRATIO(35), kSCRATIO(65));
self.showColor.backgroundColor = [UIColor colorFromHexCode:colorString];
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.showView removeFromSuperview];
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.layer.masksToBounds = NO;
self.colorStringArr = @[@"dc0000", @"f88c20", @"f4eb22", @"5ce91e", @"06a723", @"21ecfa", @"23adf5", @"0057fe", @"151de4", @"6c21f7", @"cb23f4", @"fe009e", @"f7a5b1", @"f6f6f6", @"ad6130", @"85420b", @"878586", @"414141", @"000000"];
for (int i = 0; i < self.colorStringArr.count; i++) {
CALayer *layer = [[CALayer alloc] init];
layer.frame = CGRectMake(i * kSCRATIO(15), 0, kSCRATIO(15), kSCRATIO(25));
layer.backgroundColor = [UIColor colorFromHexCode:self.colorStringArr[i]].CGColor;
[self.layer addSublayer:layer];
}
}
return self;
}
@end
Objective-C
1
https://gitee.com/wuxie8/color_slider.git
git@gitee.com:wuxie8/color_slider.git
wuxie8
color_slider
色彩滑块
master

搜索帮助