精华内容
下载资源
问答
  • hexColor

    2016-06-02 11:57:00
    hexColor + (UIColor *) colorWithHexString: (NSString *)color{ NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet...

    + (UIColor *) colorWithHexString: (NSString *)color
    {
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];

    // String should be 6 or 8 characters
    if ([cString length] < 6) {
    return [UIColor clearColor];
    }

    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
    cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
    cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
    return [UIColor clearColor];

    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;

    //r
    NSString *rString = [cString substringWithRange:range];

    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];

    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];

    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];

    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
    }


    + (UIColor *) colorFromHexCode:(NSString *)hexString {
    NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
    if ([cleanString length] == 3) {
    cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
    [cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
    [cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
    [cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
    }
    if([cleanString length] == 6) {
    cleanString = [cleanString stringByAppendingString:@"ff"];
    }

    unsigned int baseValue;
    [[NSScanner scannerWithString:cleanString] scanHexInt:&baseValue];

    float red = ((baseValue >> 24) & 0xFF)/255.0f;
    float green = ((baseValue >> 16) & 0xFF)/255.0f;
    float blue = ((baseValue >> 8) & 0xFF)/255.0f;
    float alpha = ((baseValue >> 0) & 0xFF)/255.0f;

    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
    }

    posted on 2016-06-02 11:57 苹果ios开发者 阅读(...) 评论(...) 编辑 收藏

    转载于:https://www.cnblogs.com/z-j-w/p/5552544.html

    展开全文
  • HexColor

    2016-01-06 16:27:00
    // HexColor.swift // HexColor // // Created by Tuomas Artman on 1.9.2014. // Copyright (c) 2014 Tuomas Artman. All rights reserved. // import Foundation import UIKit extension ...
    //
    //  HexColor.swift
    //  HexColor
    //
    //  Created by Tuomas Artman on 1.9.2014.
    //  Copyright (c) 2014 Tuomas Artman. All rights reserved.
    //
    
    import Foundation
    import UIKit
    
    
    extension UIColor {
        
        /// Initializes UIColor with an integer.
        ///
        /// - parameter value: The integer value of the color. E.g. 0xFF0000 is red, 0x0000FF is blue.
        public convenience init(_ value: Int) {
            let components = getColorComponents(value)
            self.init(red: components.red, green: components.green, blue: components.blue, alpha: 1.0)
        }
        
        /// Initializes UIColor with an integer and alpha value.
        ///
        /// - parameter value: The integer value of the color. E.g. 0xFF0000 is red, 0x0000FF is blue.
        /// - parameter alpha: The alpha value.
        public convenience init(_ value: Int, alpha: CGFloat) {
            let components = getColorComponents(value)
            self.init(red: components.red, green: components.green, blue: components.blue, alpha: alpha)
        }
        
        /// Creates a new color with the given alpha value
        ///
        /// For example, (0xFF0000).alpha(0.5) defines a red color with 50% opacity.
        ///
        /// - returns: A UIColor representation of the Int with the given alpha value
        public func alpha(value:CGFloat) -> UIKit.UIColor {
            var red: CGFloat = 0
            var green: CGFloat = 0
            var blue: CGFloat = 0
            var alpha: CGFloat = 0
            
            self.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
            
            return UIKit.UIColor(red: red, green: green, blue: blue, alpha: value)
        }
        
        /// Mixes the color with another color
        ///
        /// - parameter color: The color to mix with
        /// - parameter amount: The amount (0-1) to mix the new color in.
        /// - returns: A new UIColor instance representing the resulting color
        public func mixWithColor(color:UIColor, amount:Float) -> UIColor {
            var comp1: [CGFloat] = Array(count: 4, repeatedValue: 0);
            self.getRed(&comp1[0], green: &comp1[1], blue: &comp1[2], alpha: &comp1[3])
            
            var comp2: [CGFloat] = Array(count: 4, repeatedValue: 0);
            color.getRed(&comp2[0], green: &comp2[1], blue: &comp2[2], alpha: &comp2[3])
            
            var comp: [CGFloat] = Array(count: 4, repeatedValue: 0);
            for i in 0...3 {
                comp[i] = comp1[i] + (comp2[i] - comp1[i]) * CGFloat(amount)
            }
            
            return UIColor(red:comp[0], green: comp[1], blue: comp[2], alpha: comp[3])
        }
    }
    
    private func getColorComponents(value: Int) -> (red: CGFloat, green: CGFloat, blue: CGFloat) {
        let r = CGFloat(value >> 16 & 0xFF) / 255.0
        let g = CGFloat(value >> 8 & 0xFF) / 255.0
        let b = CGFloat(value & 0xFF) / 255.0
        
        return (r, g, b)
    }
    

     github地址:https://github.com/artman/HexColor

    展开全文
  • Hex color

    2020-11-30 15:11:25
    <div><p>Any possibility of adding interpolation for hex colors? I can help with this.</p><p>该提问来源于开源项目:wcandillon/react-native-redash</p></div>
  • Color Hex Color Codes

    2020-11-28 06:04:45
    <div><p>Is it possible to have the ability to enter Color Hex Color Codes as colors. It will help entering colors that you like faster. <p><img alt="color hex color codes" src=...
  • Add hex color input

    2021-01-10 02:13:17
    <div><p>This PR relates to issue #1084 and adds a hex color input to the main index page of the UI. If the hex color is not supported, a small message will appear saying "Invalid hex color." ...
  • color_change 这是HEXColor的虚拟仓库。
  • Full Hex Color Support

    2020-12-09 09:23:38
    <p>From the documentation it appears that it supports hex color notation, but deceptively only if the hex colors fall into the 256 bit spectrum. <pre><code> For example: let g:NETRColors = {'...
  • Different Hex Color Output

    2020-12-01 19:29:44
    <div><p>My hex color output seems to be different from the one in Figma. <p>SCSS File = #ec5858; Figma = #EB5757 <p><img alt="test1" src=...
  • Add Hex Color Support

    2020-12-27 17:15:30
    This PR adds hex color support to Skript through a new "color" tag. I have updated the documentation appropriately. Unlike #3078, the tag <em>should</em> work everywhere now. I had to make ...
  • This should be added because, at the moment, the hex color code requires developers to create either a class or a method just to use custom messages with hex colors. This would make a lot more sense ...
  • HexColor.h - Missing

    2021-01-12 08:25:58
    <div><p>When building for iOS6 in XCode 4.3 you get a runtime crash as HexColor.h is not in the project. <p>This will be because I'm not using Cocopods... (Was UIColor+ColorWithHex). <p>The ...
  • add usage of hex color codes

    2020-12-26 00:24:14
    <p>to use the same colors (more colors) it would be nice if you could add hex color codes instead of those few predefined colors.</p><p>该提问来源于开源项目:Gruntfuggly/todo-tree</p></div>
  • ve added the logic to process short HEX color code. I've used <code>String.prototype.repeat</code> but I doubt we need to add some polyfill for IE support for that. <p>Please advice.</p><p>该提问...
  • <div><p>Tiny addition: hex color value in the legend. Prevents having to convert it for some purposes. <p>Expanded the containing divier from 10em to 13em to make space.</p><p>该提问来源于开源项目&#...
  • <div><p>Is there a way (or consider as a feature request) to use the hex color values (#FFFFFF) in the MQTT color payload instead of RGB? <p>Many MQTT dashboards use HEX natively. <p>Thx for ...
  • <p>This always converts hex colors. It generates this kind of codes. ... How can I turn off hex color compression? <p>Very thanks.</p><p>该提问来源于开源项目:leafo/lessphp</p></div>
  • Since Paper uses a different logging system which currently outputs a garbled mess when using hex color codes, this PR aims to add that feature. The solution used is largely based on ...
  • <p>improve the config color option, set hex color value(RGB888 format) directly <h3>Benefits <h1>699 <p>...
  • 当我们打开Color面板时,会发现下面有一个Hex Color值。这个是用16进制表示的颜色值。下面就是将16进制颜色值转变成color值的代码。一.C# private Color HexToColor(string hex) 十六进制转十进制 { byte DEC_r =...

        当我们打开Color面板时,会发现下面有一个Hex Color值。这个是用16进制表示的颜色值。下面就是将16进制颜色值转变成color值的代码。

    一.C#

        

    private Color HexToColor(string hex) 十六进制转十进制
        {
            byte DEC_r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
            byte DEC_g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
            byte DEC_b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
            byte DEC_a = byte.Parse(hex.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
            //Debug.Log("DEC_r"+ DEC_r + "DEC_g"+ DEC_g+ "DEC_b"+ DEC_b);
            float r = DEC_r / 255f;
            float g = DEC_g / 255f;
            float b = DEC_b / 255f;
            float a = DEC_a / 255f;
            return new Color(r,g,b,a);
        }
    
        private string ColorToHex(Color color) //十进制转十六进制
        {
            int r = Mathf.RoundToInt(color.r*255.0f);
            int g = Mathf.RoundToInt(color.g * 255.0f);
            int b = Mathf.RoundToInt(color.b * 255.0f);
            int a = Mathf.RoundToInt(color.a * 255.0f);
            string hex = string.Format("{0:X2}{1:X2}{2:X2}{3:X2}",r,g,b,a);
            return hex;
        }

    二.LUA

        最近在学习Lua语言,就是对这个语言感兴趣,所以自己写了一个进制转换函数。代码如下:

    function HexToColor(hex)
    	local s
    	s=string.sub(hex,1,2) //截取字符串  lua的索引是从1开始
    	local r=tonumber(s,16)/255
    	s=string.sub(hex,3,4)
    	local g=tonumber(s,16)/255
    	s=string.sub(hex,5,6)
    	local b=tonumber(s,16)/255
    	s=string.sub(hex,7,8)
    	local a=tonumber(s,16)/255
    	return GetNum(r),GetNum(g),GetNum(b),GetNum(a)
    	end
    
    function GetNum(a)
    	return string.format('%0.3f',a) 截取小数位数  当截取两位,则是'%0.2f'
    	end
    
    print(HexToColor('B7C4FFFF'))
       这个lua因为是才学的,所以就把这个函数写到博客里顺便把一些知识点给记下来。可能方法不是最好的。希望本博客对你有帮助!
    展开全文
  • Add sanitize for hex color

    2020-12-09 02:50:04
    <div><p>Added <code>sanitize_hex_color</code> and <code>sanitize_hex_color_no_hash</code> to the list of sanitizing functions. <p>This was proposed here: ...
  • HEX color entry field

    2021-01-10 03:32:42
    <div><p>Maybe its just me, but I miss the quick selection color options that used to be located directly under the color wheel in the UI! Specifically, when it comes to approximating the incandescent/...
  • t yet support HEX color codes for options such as <code>weechat.color.chat_nick_colors</code> (as seen for example <a href="http://pln.jonas.me/xterm-colors">here</a>. Would be great if this could be ...
  • Added hex color support

    2020-12-29 09:22:52
    <div><p>该提问来源于开源项目:pimoroni/unicorn-hat</p></div>
  • support correct hex color

    2020-12-29 01:46:06
    <div><p>it's that basic <p>resolves #125</p><p>该提问来源于开源项目:probot/settings</p></div>
  • •Error: The HEX color value is invalid. Has to be "#XXXXXX" format.?? <p>can you help me thanks greatings</p><p>该提问来源于开源项目:pH7Software/pH7-Social-Dating-CMS</p></div>
  • Hex Color Code-crx插件

    2021-03-28 13:26:43
    语言:English 十六进制颜色代码是用于Chrome的简单且易于使用的十六进制代码生成器。 不需要权限。 十六进制颜色代码是一个有用的小颜色选择器。 获取所需每种颜色的十六进制代码。 这是一个没有任何浏览器权限的...
  • <p>It would be great to add the ability to use a color in hex as "base_color". <p>Example : <pre><code> javascript Please.make_color({ base_color: '#FF0000' }); </code></pre>该提问...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,745
精华内容 1,098
关键字:

HexColor