赞
踩
//颜色构造 -- alpha:[0,1] 0-完全透明 1-不透明
[UIColor redColor], .....
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
//设置绘制的起始位置及样式属性
- (void)drawAtPoint:(CGPoint)point withAttributes:(NSDictionary *)attrs
//设置绘制的区域及样式属性
- (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context
e.g.
- (void)drawRect:(CGRect)rect{
UIColor *textColor =[UIColor colorWithRed:0.5f green:0.0f blue:0.5f alpha:1.0f];
// UIColor *textColor = [UIColor redColor];
UIFont *helveticaBold = [UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0f];
// UIFont *helveticaBold = [UIFont boldSystemFontOfSize:30];
NSDictionary *dicAttribute = @{
NSFontAttributeName:helveticaBold,
NSForegroundColorAttributeName:textColor
};
NSString *myString = @"I Learn Really Fast";
// [myString drawAtPoint:CGPointMake(25, 190) withAttributes:dicAttribute];
CGRect textRect = CGRectMake(100, 120, 100, 200);
[myString drawWithRect:textRect options:NSStringDrawingUsesLineFragmentOrigin
attributes:dicAttribute context:nil];
}
//颜色解析-(void)colorAnalysis {
UIColor *steelBlueColor = [UIColor colorWithRed:0.3f green:0.4f blue:0.6f alpha:1.0f];
CGColorRef colorRef = steelBlueColor.CGColor;
const CGFloat *components =CGColorGetComponents(colorRef); //颜色构成
NSUInteger componentsCount =CGColorGetNumberOfComponents(colorRef);
NSUInteger counter = 0;
for (counter = 0; counter < componentsCount; counter++){
NSLog(@"Component %lu = %.02f", (unsigned long)counter + 1, components[counter]);
}
//result : Component 1 = 0.30 ......
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。