【问题标题】:UITextField placeholder font color white iOS 5?UITextField占位符字体颜色白色iOS 5?
【发布时间】:2012-05-16 18:56:29
【问题描述】:

我在 XIB 中遇到问题。我的占位符颜色的颜色在界面生成器中默认为灰色,但是当我运行应用程序时,文本的颜色为白色,我看不到它,因为背景是白色的。

有没有人可以解决这个问题?

【问题讨论】:

    标签: ios5 interface-builder uitextfield xcode4.3 placeholder


    【解决方案1】:

    您可以像这样覆盖drawPlaceholderInRect:(CGRect)rect 以手动呈现UITextField 中的占位符文本

    - (void) drawPlaceholderInRect:(CGRect)rect {
        [[UIColor blueColor] setFill];
        [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
    }
    

    【讨论】:

    • 当你覆盖时,是否意味着你必须创建一个UITextField的子类?比如,CustomTextField?
    • 我有这个错误:: CGContextSetFillColorWithColor: invalid context 0x0 请告诉我如何解决它?
    • [activeView.layer renderInContext:UIGraphicsGetCurrentContext()];
    【解决方案2】:

    上述解决方案对我不起作用,我使用了以下解决方法。

    [UILabel appearanceWhenContainedIn:[UITextField class], nil] setTextColor:[UIColor darkGrayColor]];
    

    但后来我知道了另一个错误,上面的工作完成了,但它也将所有其他标签的颜色重置为默认黑色。然后我必须将 UILabel 类作为子类,并在我的视图中的所有其他标签中使用我的类。

    【讨论】:

      【解决方案3】:

      快速修正语法:

      [[UILabel appearanceWhenContainedIn:[UITextField class], nil] setTextColor:[UIColor darkGrayColor]];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-12
        • 1970-01-01
        • 2014-06-12
        • 2014-06-03
        • 2014-01-31
        • 1970-01-01
        • 2012-04-12
        • 2010-11-23
        相关资源
        最近更新 更多