willc2
willc2

Reputation: 39671

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

If so, can the image be animated?

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

Upvotes: 3

Views: 1642

Answers (1)

willc2
willc2

Reputation: 39671

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.

Upvotes: 6

Related Questions