【问题标题】:Change UITextField's placeholder text color using Userattributes?使用用户属性更改 UITextField 的占位符文本颜色?
【发布时间】:2014-01-16 07:43:02
【问题描述】:

我想从用户属性(界面构建器)更改占位符颜色,因为我不想子类化我的 UITextfield 等...我在互联网上搜索并找到了这个“_placeholderLabel.textColor”是的,这在编程上很有效[self.tfEmail setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"]; 但是我想在界面生成器的用户属性中使用它。

【问题讨论】:

    标签: ios objective-c uitextfield


    【解决方案1】:

    尝试删除“_”,

    为我工作。

    【讨论】:

    • 大声笑我从来没有机会在界面生成器中使用这样的占位符!啊哈太棒了,我想知道你还能用同样的方法创造什么
    • 简直太棒了..!!好朋友。
    • 您可以更改字体,您可以更改任何存在的属性。无需以编程方式进行。
    • @Xeieshan,是只用于 UITextField 还是任何控件?
    【解决方案2】:

    不使用用户属性

     self.txtField.attributedPlaceholder = PlaceHolderAttributedString(@"ABCDEF");
    

    其中 PlaceHolderAttributedString 是一个宏定义为

     #define PlaceHolderAttributedString(placeHolderText) [[NSAttributedString alloc] initWithString:placeHolderText attributes:@{NSForegroundColorAttributeName:ColorTextFieldPlaceHolder}]
    

    使用用户属性

     placeholderLabel.textColor 
    

    【讨论】:

      【解决方案3】:

      迅速:

          one_textfield.setValue(UIColor.redColor(), forKeyPath: "_placeholderLabel.textColor")
      

      【讨论】:

        猜你喜欢
        • 2010-11-23
        • 2014-06-12
        • 2012-04-12
        • 2014-11-22
        • 2011-11-11
        • 1970-01-01
        • 1970-01-01
        • 2017-05-18
        • 2013-02-04
        相关资源
        最近更新 更多