2014-06-17 37 views
0

所以我想在Parse LoginView控制器中更改用戶名佔位符,但文本顯示爲模糊 - 如何設置正確的陰影/高光或...只需更改文本而不更改樣式屬性。下面在解析loginviewcontroller中更改佔位符文本

https://parse.com/tutorials/login-and-signup-views

這兩個創建一個沒有正確的陰影模糊灰色文本/凸顯

logInViewController.logInView.usernameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Phone" attributes:@{}]; 

logInViewController.logInView.usernameField.placeholder = @"phone"; 

回答

0

我不知道你要應用的效果(有幾個例子/截圖在你的鏈接上)。
但在這裏你可以做或者設置爲你想了什麼(應用所需的值):

NSAttributedString *originalUserNamePlaceHolder = logInViewController.logInView.usernameField.attributedPlaceholder; 

NSShadow *shadow = [[NSShadow alloc] init]; 
[shadow setShadowBlurRadius:2.0]; 
[shadow setShadowColor:[UIColor grayColor]]; 
[shadow setShadowOffset:CGSizeMake(0, 2.0)]; 

NSDictionary *attributesCustom = @{NSShadowAttributeName: shadow, NSForegroundColorAttributeName:theUIColorYouWant}; 
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"customText" attributes: attributesCustom]; 
logInViewController.logInView.usernameField.attributedPlaceholder = attrString; 

注意customText可能是[originalUserNamePlaceHolder string];

你可以閱讀更多關於你的婉的各種效果適用here。現在

,你可以這樣做來檢索要模仿(因爲你喜歡它)的設置,檢索其具體設置:

__block NSDictionary *attributesRetrieved; 
[attrString enumerateAttributesInRange:NSMakeRange(0, [attrString length]) options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) 
{ 
    NSLog(@"Attrs: %@", attrs); 
    attributesRetrieved = [attrs copy]; 
}]; 

應該只有一個屬性(對於整個文本)。 例如,在一個我設置: 你有:

attributesRetrieved:{
NSColor = 「1 UIDeviceWhiteColorSpace 1」;
NSShadow =「NSShadow {0,2} blur = 2 color = {UIDeviceWhiteColorSpace 0.5 1}」;
} 因此,您可以檢索之前放置的設置。