2014-01-08 22 views
0

任何人都可以請示例解釋我如何使用UITextField defaultTextAttribute屬性?我搜查了很多,但沒有找到一個例子。我認爲它是添加在IOS 7.0多數民衆贊成爲什麼!我們如何使用UITextField的defaultTextAttribute?

在此先感謝

+0

參見[蘋果文檔。 for defaultTextAttribute of UITextField](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/doc/uid/TP40006888-CH3-SW61) –

回答

1

如果使用defaultTextAttributes屬性,你會得到一個唯一的詞典。如果你想設置,那麼你必須做一些事情是這樣的:

NSString *s = @"Why?"; 
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:s]; 
NSInteger _stringLength=[s length]; 
UIColor *_red=[UIColor redColor]; 
[attString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:25] range:NSMakeRange(0, _stringLength)]; 
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)]; 
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, _stringLength)]; 
self.textField.attributedText = attString; 

鋤頭這會有所幫助.. :)

+0

+1爲好答案! – Retro

+0

您可以在這裏找到屬性列表以及設置它們的內容。 https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/index.html#//apple_ref/doc/constant_group/Character_Attributes –

0

默認情況下,此屬性返回文本的字典,默認的屬性值。

設置此屬性將指定的屬性應用於文本字段的整個文本。未設置的屬性保持其默認值。

獲取此屬性返回以前設置的屬性,這些屬性可能已通過設置屬性(如font和textColor)進行了修改。

NSDictionary* textFieldAttrib = [textField defaultTextAttributes]; 

這會告訴你預設的性能

+0

Can我還設置了defaultTextAttribute屬性?如果是,那麼如何? – shankywave1

+0

是的,你可以做到這一點,看看@Rashad回答 – Retro