UITextAttributeTextShadowOffset已弃用

Ben*_*ter 12 iphone xcode objective-c ios ios7

我试图将我的代码添加到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)]
Run Code Online (Sandbox Code Playgroud)

我得到了一些错误,UITextAttributeColor is deprecated,UITextAttributeTextShadowColor is deprecated,和UITextAttributeTextShadowOffset is deprecated.

Leo*_*ica 32

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]
}];
Run Code Online (Sandbox Code Playgroud)


小智 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];
Run Code Online (Sandbox Code Playgroud)