• 十六进制颜色转换为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

  • 相关阅读:
    spring mvc 分页
    get/post时中文乱码问题的解决办法
    mysql-day01
    servler配置
    idea
    springMvc 核心配置
    ServletRequest面试题
    Servlet面试题
    Http面试题
    测试文件
  • 原文地址:https://www.cnblogs.com/dongdongyuan/p/4921631.html
Copyright © 2020-2023  润新知