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

元气小坏坏 提交于 2019-11-30 18:06:35

问题


If so, can the image be animated?

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


回答1:


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.



来源:https://stackoverflow.com/questions/1025304/can-text-in-uilabel-have-a-colorwithpatternimage-assigned-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!