登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

透过空白区域点击叠加在一起的图片,获取图片中不同颜色

[复制链接]
来自: 展翅玖霄TF 分类: iOS精品源码 上传时间: 2016-6-30 19:31:01
Tag:按钮 button 颜色 color 图片

项目介绍:

文:tf1106285167/Button_ThroughBlankArea(github)
透过空白区域点击叠加在一起的图片,获取图片中不同颜色



主要集成代码:
[Objective-C] 查看源文件 复制代码
#import "ViewController.h"
#import "OBShapedButton.h"

#define KScreenWidth [UIScreen mainScreen].bounds.size.width
#define KScreenHeight [UIScreen mainScreen].bounds.size.height
#define MainURL  @"http://m.zlifan.com/"
@interface ViewController ()
{
    UILabel *content3Label;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *imgArr = @[@"yuan",@"yuanTxt"];
    
    CGFloat imgWH = 240;
    OBShapedButton *obshapBtn;
    for (int i=0; i<imgArr.count; i++) {
       
        obshapBtn = [[OBShapedButton alloc]initWithFrame:CGRectMake((KScreenWidth-240)/2, (KScreenHeight-240)/2, imgWH, imgWH)];;
        obshapBtn.tag = 200+i;
        
        //取消长按变灰
        obshapBtn.adjustsImageWhenHighlighted = NO;
        [self.view addSubview:obshapBtn];
        [obshapBtn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateNormal];
        obshapBtn.layer.cornerRadius = imgWH/2;
        [obshapBtn addTarget:self action:@selector(imgAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    UIView *view3Back = [[UIView alloc]initWithFrame:CGRectMake(97, 226-60, imgWH-88, imgWH-88)];
    view3Back.layer.cornerRadius = (imgWH-88)/2;
    view3Back.center = obshapBtn.center;
    view3Back.tag = 250;
    view3Back.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view3Back];
    
    content3Label = [[UILabel alloc]initWithFrame:CGRectMake(120, 250, imgWH-120, imgWH-150)];
    content3Label.font = [UIFont systemFontOfSize:15];
    content3Label.textColor = [UIColor blackColor];
    content3Label.center = obshapBtn.center;
    content3Label.textAlignment = NSTextAlignmentCenter;
    content3Label.numberOfLines = 0;
    content3Label.text = @"只需反馈一次,\n问题就能解决";
    [self.view addSubview:content3Label];

}

-(void)imgAction:(UIButton *)btn{
    
    UIView *view = [self.view viewWithTag:250];
    
    NSString *url = [NSString stringWithFormat:@"%@images/yuan/yuan.jsp",MainURL];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *diction = [defaults objectForKey:@"pixelColor"];
    
    NSArray *array1 = [str componentsSeparatedByString:@","];
    
    CGFloat r = [diction[@"colorRed"] floatValue];
    CGFloat g = [diction[@"colorGreen"] floatValue];
    CGFloat b = [diction[@"colorBlue"] floatValue];
    CGFloat alpha = [diction[@"colorAlpha"] floatValue];
    
    if (!(r == 0 && g == 0 && b == 0) && !(r ==255 && g ==255 && b ==255) && alpha == 1) {
        
        view.backgroundColor = [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1];
        NSInteger colorInt = [self redName:r WithGreenName:g WithBlueName:b];
        
        for (int i=0; i<array1.count; i++) {
            
            NSString *content = array1[i];
            if([content rangeOfString:[NSString stringWithFormat:@"%ld",(long)colorInt]].location !=NSNotFound)//_roaldSearchText
            {
                
                NSArray *array2 = [content componentsSeparatedByString:@":"];
                NSString *content2 = [array2[1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
                content2 = [content2 stringByReplacingOccurrencesOfString:@"}" withString:@""];
                content3Label.text = content2;
            }
        }
    }
}

-(NSInteger)redName:(NSInteger)red WithGreenName:(NSInteger)green WithBlueName:(NSInteger)blue{
    
    return (0xFF << 24) | (red << 16) | (green << 8) | blue;
}


DEMO 直接下载:

相关源码推荐:

我来说两句
*滑动验证:
所有评论(30)
AlonMessi 2016-7-1 11:10:00
学习...学习...
回复
BlueManlove 2016-7-1 11:11:10
支持,感谢,祝code4app越来越好~
回复
phoiu 2016-7-1 11:12:19
code4app好的代码demo真的很多,谢谢啦~
回复
kengsir 2016-7-1 11:13:40
不错不错,楼主辛苦了。。。
回复
hellokenken 2016-7-1 11:17:02
感谢大神分享,必须顶!
回复
littleRed 2016-7-1 11:23:37
mark,收藏了
回复
zhangdongdong 2016-7-1 13:41:31
楼主威武啊,Code4App有你更给力!
回复
ly站牌 2016-7-1 13:45:33
很给力,Code4App有你更精彩!
回复
Ediosn 2016-7-1 13:49:13
~~~~~~~~~~~
回复
1234下一页
提取码:  下载次数:31 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
963 0 31
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表