Can text in UILabel have a colorWithPatternImage: assigned to it?

前端 未结 1 1773
遥遥无期
遥遥无期 2021-01-06 13:45

If so, can the image be animated?

Is there a good reason not to do this? Memory usage, etc?

相关标签:
1条回答
  • 2021-01-06 14:18

    Yes, a label can have a pattern color.

    alt text http://img178.imageshack.us/img178/1995/textwithpatterncolor.png

    // make a UIColor with an image as the pattern
    UIImage *tileImage = [UIImage imageNamed:@"hot_grad_64px.png"];
    UIColor *patternColorTile = [UIColor colorWithPatternImage:tileImage];
    
    // assign it to the .textColor property of a UILabel
    self.testLabel.textColor = patternColorTile;
    
    // the pattern will only align if both the .frame property of the 
    // label AND the font size is the same as the image tile height
    

    The pattern can be animated by switching between multiple pattern colors. I have flipped between a pattern image and a plain color at > 30fps and the iPhone device kept up fine.

    As long as the image tile is small, I don't see any reason not to do this, but I haven't extensively profiled it.

    0 讨论(0)
提交回复
热议问题