IOS Universal Color Quick Generate code

Source: Internet
Author: User
Tags color representation

Usually we are directly using similar to #EE1289这样的代码来直接表示RGB颜色的. But in the iOS language, its color representation is more alternative, he uses a 0-1 decimal to represent the color value. Such an implementation may be able to represent more color values, but it undoubtedly increases the amount of code for the program staff. When we get #EE1289时, this is usually called.

?
1 [UIColor colorWithRed:0xEE/255.0 green:0x12/255.0 blue:0x89/255.0 alpha:1];

This invocation is really cumbersome, so encapsulate a small method to call directly

?
1 2 3 4 5 6 /*  *  获取颜色  */ +(UIColor *)colorWithRGB:(int)color alpha:(float)alpha{     return [UIColor colorWithRed:((Byte)(color >> 16))/255.0 green:((Byte)(color >> 8))/255.0 blue:((Byte)color)/255.0 alpha:alpha];}

When using the above method, the calling format is as follows:

?
1 [UIColor colorWithRGB:0xEE1289 alpha:1]

Convenient for many.

Related Article

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.