UITextAttributeTextShadowOffset已经被弃用。

13

我正在努力将我的代码适应iOS 7。

 [[UIBarButtonItem appearance] setTitleTextAttributes:@{
                            UITextAttributeTextColor: [UIColor colorWithRed:214.0f/255.0f green:210.0f/255.0f blue:197.0f/255.0f alpha:1.0f],
                      UITextAttributeTextShadowColor: [UIColor colorWithWhite:0.0f alpha:0.750f],
                     UITextAttributeTextShadowOffset: [NSValue valueWithCGSize:CGSizeMake(0.0f, 1.0f)]

我遇到了几个错误:UITextAttributeColor被弃用了UITextAttributeTextShadowColor被弃用了,以及 UITextAttributeTextShadowOffset被弃用了


点击此处:https://dev59.com/QWMk5IYBdhLWcg3wyw0U - user2632844
3个回答

34
NSShadow *shadow = [NSShadow new];
[shadow setShadowColor: [UIColor colorWithWhite:0.0f alpha:0.750f]];
[shadow setShadowOffset: CGSizeMake(0.0f, 1.0f)];

[[UIBarButtonItem appearance] setTitleTextAttributes:@{
  NSForegroundColorAttributeName: [UIColor colorWithRed:214.0f/255.0f green:210.0f/255.0f blue:197.0f/255.0f alpha:1.0f],
  NSShadowAttributeName: shadow]
}];

6
NSShadow *shadow = [NSShadow new];
[shadow setShadowColor : [UIColor colorWithWhite:0.0f alpha:0.750f]];
[shadow setShadowOffset : CGSizeMake(0.0f, 1.0f)];

[[UITabBarItem appearance] setTitleTextAttributes:
@{ 
    NSFontAttributeName : [UIFont fontWithName:@"AmericanTypewriter" size:10.0f],
    NSForegroundColorAttributeName : [UIColor grayColor],
    NSShadowAttributeName: shadow
}
forState:UIControlStateNormal];

[[UITabBarItem appearance] setTitleTextAttributes:
@{ 
    NSFontAttributeName : [UIFont fontWithName:@"AmericanTypewriter" size:10.0f],
    NSForegroundColorAttributeName : [UIColor blackColor],
    NSShadowAttributeName : shadow
}
forState:UIControlStateSelected];

这个答案结构不太好,很难理解。你能否解释一下这个符号的含义?现在这样可能没有什么用。 - Trilarion
实际上这是一个相当不错的代码示例,但同意它缺少解释。 - JOM

2
UIColor *blue = [UIColor colorWithRed:64.0/255.0
                                green:119.0/255.0
                                 blue:255.0/255.0
                                alpha:1.0];

NSShadow *shadow = [NSShadow.alloc init];
shadow.shadowColor = [UIColor clearColor];

NSDictionary *attributes = @{
                              NSForegroundColorAttributeName: blue,
                              NSShadowAttributeName: shadow
                              };

[[UIBarButtonItem appearance] setTitleTextAttributes:attributes
                                            forState:UIControlStateNormal];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接