zoukankan      html  css  js  c++  java
  • IOS之UIColor

    转自:http://blog.csdn.net/wudizhukk/article/details/8607229

    UIColor常见用法,废话少说 直接网上抄来记录下,凭空想还真有点想不起来,最近记忆力不好,所以记着点。

    1. UIColor *myWhiteTransparentColor = [ UIColor colorWithWhite: 1.0 alpha: 0.50 ];  
    2.  
    3. UIColor *myColorHue = [ UIColor colorWithHue: 120.0 / 360.0  
    4.         saturation: 0.75  
    5.         brightness: 0.50  
    6.         alpha: 1.0  
    7. ];  
    8.  
    9. UIColor *myColorRGB = [ UIColor colorWithRed: 0.75  
    10.         green: 1.0  
    11.         blue: 0.75  
    12.         alpha: 1.0  
    13. ]; 

    如果你打算重用许多不同的UIColor对象,你也可以创建它们的实例:

    1. UIColor *myWhiteTransparentColor = [ [ UIColor alloc ]  
    2.         initWithWhite: 1.0 alpha: 0.50  
    3. ];  
    4.  
    5. UIColor *myColorHue = [ [ UIColor alloc ]  
    6.         initWithHue: 120.0 / 360.0  
    7.         saturation: 0.75  
    8.         brightness: 0.50  
    9.         alpha: 1.0  
    10. ];  
    11.  
    12. UIColor *myColorRGB = [ [ UIColor alloc ] initWithRed: 0.75  
    13.         green: 1.0  
    14.         blue: 0.75  
    15.         alpha: 1.0  
    16. ]; 

    UIColor类还支持许多静态方法,可以创建系统颜色,这些颜色都经过iPhone的校正,以达到尽可能准确的地步。这些方法如下所示,均来自UIColor.h:

    1. + (UIColor *)blackColor;        // 0.0 白色  
    2. + (UIColor *)darkGrayColor;     // 0.333 白色  
    3. + (UIColor *)lightGrayColor;    // 0.667 白色  
    4. + (UIColor *)whiteColor;        // 1.0 白色  
    5. + (UIColor *)grayColor;         // 0.5 白色  
    6. + (UIColor *)redColor;          // 1.0, 0.0, 0.0 RGB  
    7. + (UIColor *)greenColor;        // 0.0, 1.0, 0.0 RGB  
    8. + (UIColor *)blueColor;         // 0.0, 0.0, 1.0 RGB  
    9. + (UIColor *)cyanColor;         // 0.0, 1.0, 1.0 RGB  
    10. + (UIColor *)yellowColor;       // 1.0, 1.0, 0.0 RGB  
    11. + (UIColor *)magentaColor;      // 1.0, 0.0, 1.0 RGB  
    12. + (UIColor *)orangeColor;       // 1.0, 0.5, 0.0 RGB  
    13. + (UIColor *)purpleColor;       // 0.5, 0.0, 0.5 RGB  
    14. + (UIColor *)brownColor;        // 0.6, 0.4, 0.2 RGB  
    15. + (UIColor *)clearColor;        // 0.0 白色, 0.0 alpha 

    创建好UIColor对象之后,就可以将其赋给文本视图的色彩属性了:

    textView.textColor = myColorHue;

    从UIColor中得到 RGB 各个值

    CGFloat R, G, B;
     
    UIColor *uiColor = [lblDate textColor];
    CGColorRef color = [uiColor CGColor];
    int numComponents = CGColorGetNumberOfComponents(color);
     
    if (numComponents == 4)
    {
    	const CGFloat *components = CGColorGetComponents(color);
    	 R = components[0];
    	 G = components[1];
    	 B = components[2];
    }
  • 相关阅读:
    Using Resource File on DotNet
    C++/CLI VS CSharp
    JIT VS NGen
    [Tip: disable vc intellisense]VS2008 VC Intelisense issue
    UVa 10891 Game of Sum(经典博弈区间DP)
    UVa 10723 Cyborg Genes(LCS变种)
    UVa 607 Scheduling Lectures(简单DP)
    UVa 10401 Injured Queen Problem(简单DP)
    UVa 10313 Pay the Price(类似数字分解DP)
    UVa 10635 Prince and Princess(LCS N*logN)
  • 原文地址:https://www.cnblogs.com/LCGIS/p/3337580.html
Copyright © 2011-2022 走看看