zoukankan      html  css  js  c++  java
  • iOS 通过HEX(十六进制)得到一个UIColor的对象






    inline static UIColor* getColorFromHex(NSString *hexColor)
    {
        
        if (hexColor == nil) {
            return nil;
        }
        
        unsigned int red, green, blue;
        NSRange range;
        range.length = 2;
        
        range.location = 1; 
        [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
        range.location = 3; 
        [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
        range.location = 5; 
        [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];	
        
        return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
    }


  • 相关阅读:
    N-Queens
    Pow(x, n)
    Maximum Subarray
    Spiral Matrix
    Jump Game
    Merge Intervals
    Insert Interval
    Length of Last Word
    Spiral Matrix II
    Amazon 面经
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5087963.html
Copyright © 2011-2022 走看看