当前位置:   article > 正文

Drawing Text(二)绘制文本,颜色的使用_drawtext函数如何带颜色

drawtext函数如何带颜色

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

}


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/176118
推荐阅读
相关标签
  

闽ICP备14008679号