2013-09-27 218 views
11

Tôi cố gắng để addapt mã của tôi lên iOS 7.UITextAttributeTextShadowOffset được dùng nữa

[[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)] 

Tôi nhận được một vài lỗi, UITextAttributeColor is deprecated, UITextAttributeTextShadowColor is deprecated, và UITextAttributeTextShadowOffset is deprecated.

+0

Bấm vào đây: http: //stackoverflow.com/questions/18968305/ios-7-only-app-crashes-at-startup – user2632844

Trả lời

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] 
}]; 
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]; 
5
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]; 
+0

Câu trả lời này không phải là rất tốt có cấu trúc và khó hiểu. Bạn có thể giải thích một chút ý nghĩa của nó không? Vì nó là nó # s có lẽ không phải là rất hữu ích. – Trilarion

+0

Thực ra đó là một mẫu mã khá tốt, nhưng đồng ý rằng nó thiếu các giải thích – JOM