【问题标题】:Can text in UILabel have a colorWithPatternImage: assigned to it?UILabel 中的文本可以有一个 colorWithPatternImage: 分配给它吗?
【发布时间】:2009-06-22 02:44:09
【问题描述】:

如果可以,图片可以动画吗?

有充分的理由不这样做吗?内存使用等?

【问题讨论】:

    标签: iphone image iphone-sdk-3.0


    【解决方案1】:

    是的,标签可以有图案颜色。

    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
    

    可以通过在多种图案颜色之间切换来为图案设置动画。我以 > 30fps 的速度在图案图像和纯色之间切换,并且 iPhone 设备保持正常。

    只要图像块很小,我看不出有什么理由不这样做,但我没有对它进行广泛的分析。

    【讨论】:

    • 随着字体变大,这种填充颜色会被拉伸和缩放,很有趣,知道如何解决这个问题吗?
    • @PsychoDad 只是调整纹理图像的大小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    相关资源
    最近更新 更多