2016-08-13 33 views
1

假設我有一個這樣的文字「通過註冊我同意Rue.Du.8中的使用條款和隱私政策」,在UITextField的內部,我希望使整個顏色灰色除了「使用條款」之外爲白色。是否有可能實現UITextField如何突出顯示UITextField中的文本部分?

enter image description here

在此先感謝...

+0

看到這個http://stackoverflow.com/questions/27728466/use-multiple-font-colors-in-a-single-label-swift –

+0

我會用一個文本視圖,這樣就可以使條款使用和隱私鏈接的工作。文本字段沒有該功能。 –

回答

3

爲此,您可以使用attributedPlaceholder財產,首先要創建一個AttributedString,像這樣。

var str = "By signing up I agree to the Terms of use and Privacy policy of Rue.Du.8" 
var attributedString = NSMutableAttributedString(string: str) 
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.grayColor(), range: (str as NSString).rangeOfString(str)) 
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor(), range: (str as NSString).rangeOfString("Terms of use")) 
self.textField.attributedPlaceholder = attributedString 
+0

完美地工作.. –

+0

謝謝@BhavinRamani :) –

+0

如此輝煌,謝謝:) –