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 is deprecated,UITextAttributeTextShadowColor is deprecatedUITextAttributeTextShadowOffset is deprecated.

4

3 回答 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]
}];
于 2013-09-27T04:46:42.460 回答
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];
于 2015-01-30T11:50:13.083 回答
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];
于 2013-10-29T12:07:36.360 回答