zoukankan      html  css  js  c++  java
  • 十六进制颜色转换为iOS可以用的UIColor

    //

    //  UIColor+Transformation.h

    //  ContactApp

    //

    //  Created by 袁冬冬 on 15/9/11.

    //  Copyright (c) 2015 . All rights reserved.

    //

     

    #import <UIKit/UIKit.h>

     

    @interface UIColor (Transformation)

    + (UIColor *)transformat:(NSString *)colorString;

    @end

     

     

     

    //

    //  UIColor+Transformation.m

    //  ContactApp

    //

    //  Created by 袁冬冬 on 15/9/11.

    //  Copyright (c) 2015 . All rights reserved.

    //

     

    #import "UIColor+Transformation.h"

     

    @implementation UIColor (Transformation)

    + (UIColor *)transformat:(NSString *)colorString {

        //去掉十六进制的#例如(#FFFFFF

        NSString *newColorString = [colorString substringFromIndex:1];

         NSRange r1 = {0,2};

         NSRange r2 = {2,2};

         NSRange r3 = {4,2};

        NSString *redStr = [newColorString substringWithRange:r1];

        NSString *greenStr = [newColorString substringWithRange:r2];

        NSString *blueStr = [newColorString substringWithRange:r3];

        ColorBlock([redStr substringToIndex:1]);

        int red = [ColorBlock([redStr substringToIndex:1]) intValue] * 16 + [ColorBlock([redStr substringFromIndex:1]) intValue];

        int green = [ColorBlock([greenStr substringToIndex:1]) intValue] * 16 + [ColorBlock([greenStr substringFromIndex:1]) intValue];

        int blue = [ColorBlock([blueStr substringToIndex:1]) intValue] * 16 + [ColorBlock([blueStr substringFromIndex:1]) intValue];

        float r = red / 255.0;

        float g = green / 255.0;

        float b = blue / 255.0;

        UIColor *c = [UIColor colorWithRed:r green:g blue:b alpha:1.0];

        return c;

    }

    NSString * (^ColorBlock)(NSString *) = ^(NSString *str) {

        if([str isEqualToString:@"A"]){

            str = @"10";

        }else if ([str isEqualToString:@"B"]){

            str = @"11";

        }else if ([str isEqualToString:@"C"]){

            str = @"12";

        }

        else if ([str isEqualToString:@"D"]){

            str = @"13";

        }

        else if ([str isEqualToString:@"E"]){

            str = @"14";

        }else if ([str isEqualToString:@"F"]){

            str = @"15";

        }

        return str;

    };

    @end

  • 相关阅读:
    呈现系统-组件间的通信方式(7)
    web项目中图标的前端处理方案
    ADO--数据访问技术
    canvas--绘制路径
    canvas--改变颜色
    canvas-在画布中画两个方块(一个空心一个实体)
    canvas--画布《第一步》
    拼图游戏【简单】
    判断字符串是否为空--string.Empty、string=""、s.length==0
    判断Char是否为数字
  • 原文地址:https://www.cnblogs.com/dongdongyuan/p/4921631.html
Copyright © 2011-2022 走看看