Drawing Text(二)绘制文本,颜色的使用

//颜色构造 -- 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 ......

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值