UIColor 进阶
来源:互联网 发布:mac 系统变慢 编辑:程序博客网 时间:2024/04/30 07:07
多说,请先看头文件:
#import <Foundation/Foundation.h>#import <CoreGraphics/CoreGraphics.h>#import <CoreImage/CoreImage.h>#import <UIKit/UIKitDefines.h>@class UIImage;UIKIT_CLASS_AVAILABLE(2_0) @interface UIColor : NSObject <NSCoding> { @private}// Convenience methods for creating autoreleased colors+ (UIColor *)colorWithWhite:(CGFloat)white alpha:(CGFloat)alpha;+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;+ (UIColor *)colorWithCGColor:(CGColorRef)cgColor;+ (UIColor *)colorWithPatternImage:(UIImage *)image;+ (UIColor *)colorWithCIColor:(CIColor *)ciColor __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);// Initializers for creating non-autoreleased colors- (UIColor *)initWithWhite:(CGFloat)white alpha:(CGFloat)alpha;- (UIColor *)initWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;- (UIColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;- (UIColor *)initWithCGColor:(CGColorRef)cgColor;- (UIColor *)initWithPatternImage:(UIImage*)image;- (UIColor *)initWithCIColor:(CIColor *)ciColor __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);// 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; // 0.0 white, 0.0 alpha // Set the color: Sets the fill and stroke colors in the current drawing context. Should be implemented by subclassers.- (void)set;// Set the fill or stroke colors individually. These should be implemented by subclassers.- (void)setFill;- (void)setStroke;// Convenience methods for getting components.// If the receiver is of a compatible color space, any non-NULL parameters are populated and 'YES' is returned. Otherwise, the parameters are left unchanged and 'NO' is returned.- (BOOL)getWhite:(CGFloat *)white alpha:(CGFloat *)alpha;- (BOOL)getHue:(CGFloat *)hue saturation:(CGFloat *)saturation brightness:(CGFloat *)brightness alpha:(CGFloat *)alpha;- (BOOL)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha;// Returns a color in the same color space as the receiver with the specified alpha component.- (UIColor *)colorWithAlphaComponent:(CGFloat)alpha;// Access the underlying CGColor or CIColor.@property(nonatomic,readonly) CGColorRef CGColor;@property(nonatomic,readonly) CIColor *CIColor;@end@interface CIColor(UIKitAdditions)- (id)initWithColor:(UIColor *)color __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);@end
有时候美工给的是十六进制的颜色值,所以我写了个方法来进行转化:
// UIColor+UIColor.h#import <UIKit/UIKit.h>@interface UIColor (UIColor)+ (UIColor *)colorWithHexValue:(NSUInteger)hexValue alpha:(CGFloat)alpha;//eg. self.window.backgroundColor = [UIColor colorWithHexValue:0x123456 alpha:0.8];@end
#import "UIColor+UIColor.h"@implementation UIColor (UIColor)+ (UIColor *)colorWithHexValue:(NSUInteger)hexValue alpha:(CGFloat)alpha{ return [UIColor colorWithRed:((hexValue >> 16) & 0x000000FF)/255.0f green:((hexValue >> 8) & 0x000000FF)/255.0f blue:((hexValue) & 0x000000FF)/255.0 alpha:alpha];}@end
- UIColor 进阶
- UIColor
- UIColor
- UIColor
- UIColor
- UIColor
- UIColor
- UIColor
- UIColor
- UIColor
- uicolor 扩充
- UIColor.h
- UIColor colorWithPatternImage
- UIColor 工具
- iOS UIColor
- UIColor扩展
- UIColor方法
- UIColor详解
- 编程之美——找符合条件的整数
- 弱联系的强度:人脉、信息和创新
- 使用stringstream对象简化类型转换
- tomcat 7.0 由于开启manager和密码设置简单被上传木马--亲身经历
- js中对css语法的操作对照表
- UIColor 进阶
- Linux中select()函数简易分析
- 海思科技完成高阶手机处理器开发 抗衡联发科
- linux socket 编程(C语言)
- java.lang.OutOfMemoryError PermGen space及其解决方法
- Ant 如何配置ant环境变量
- 传智播客网页平面设计学院一期徐同学传智对我来说我职业规划的一个转折点 !
- 科学的实践时代---2. 科学研究的目的
- 消息提示框淡入淡出效果js类