所以我想在Parse LoginView控制器中更改用户名占位符,但文本显示为模糊 - 如何设置正确的阴影/高亮...或只是更改文本而不更改样式属性
https://parse.com/tutorials/login-and-signup-views
下面这两个都会创建没有右阴影/高光的模糊灰色文本
logInViewController.logInView.usernameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Phone" attributes:@{}];
logInViewController.logInView.usernameField.placeholder = @"phone";
答案 0 :(得分: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 =" UIDeviceWhiteColorSpace 1 1&#34 ;;
NSShadow =" NSShadow {0,2} blur = 2 color = {UIDeviceWhiteColorSpace 0.5 1}&#34 ;;
} 所以你可以检索我之前的设置。