IOS Dev (26) Get a basic understanding of Uicolor's most common knowledge

Source: Internet
Author: User

    • CSDN da Rui elder brother
    • Address: Http://blog.csdn.net/prevention

-

What are the built-in colors?
// Some convenience methods to create colors.  These colors will be as calibrated as possible.// These colors are cached.+ (UIColor *)blackColor;      // 0.0 white + (UIColor *)darkGrayColor;   // 0.333 white + (UIColor *)lightGrayColor;  // 0.667 white + (UIColor *)whiteColor;      // 1.0 white + (UIColor *)grayColor;       // 0.5 white + (UIColor *)redColor;        // 1.0, 0.0, 0.0 RGB + (UIColor *)greenColor;      // 0.0, 1.0, 0.0 RGB + (UIColor *)blueColor;       // 0.0, 0.0, 1.0 RGB + (UIColor *)cyanColor;       // 0.0, 1.0, 1.0 RGB + (UIColor *)yellowColor;     // 1.0, 1.0, 0.0 RGB + (UIColor *)magentaColor;    // 1.0, 0.0, 1.0 RGB + (UIColor *)orangeColor;     // 1.0, 0.5, 0.0 RGB + (UIColor *)purpleColor;     // 0.5, 0.0, 0.5 RGB + (UIColor *)brownColor;      // 0.6, 0.4, 0.2 RGB + (UIColor *)clearColor;      

How do you use them? Very simple:

UIColor *color = [UIColor redColor];
As a designer, can you specify RGB?

Of course:

+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;

This is also very easy to understand, the attention is red and green yellow and transparency, are in the range of 0 to 1.

As a professional designer, can you specify HSB?

Of course:

+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;

The meaning should be more clear:

    • Hue Hue
    • Saturation of saturation
    • Brightness brightness
Use pictures to make colors?

Actually still use the picture ... Many people are prone to ambiguity when it comes to understanding the function name.

+ (UIColor *)colorWithPatternImage:(UIImage *)image;

Application Scenarios:

UIImage *bgImage = [UIImageimageWithContentsOfFile:@"...\background.png"];UIColor *bgColor = [UIColor colorWithPatternImage:bgImage];self.backgroundColor =bgColor;
Gets a color after the current color changes transparency

The method signature is:

colorWithAlphaComponent

Application Scenarios:

UIColor *color = [UIColor redColor];UIColor *cl = [color colorWithAlphaComponent:0.5f];

-

Reprint please specify from: http://blog.csdn.net/prevention

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.