2013-10-10 29 views
10

Tôi đang cố gắng để setSelectedImageTintColor trong iOS 7, nhưng nó không hoạt động. Dưới đây là đoạn code mà tôi có trong AppDelegate.m tôi dưới didFinishLaunchingWithOptionssetSelectedImageTintMàu không hoạt động trong iOS 7

UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController; 
UITabBar *tabBar = tabBarController.tabBar; 

for (UITabBarItem *item in tabBar.items) 
    { 
     UIImage *image = item.image; 
     UIImage *correctImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
     item.image = correctImage; 
    } 

[[UITabBar appearance] setTintColor:[UIColor whiteColor]]; 
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:44.0/255.0 green:176.0/255.0 blue:28.0/255.0 alpha:1.0]]; 
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0]]; 

Nó vẫn sẽ không hiển thị selectedImageTintColor. Màu trắng khi được chọn; màu xám khi không được chọn. Tôi đang làm gì sai?

Trả lời

15

Đây là sự cố đã biết trong iOS 7. tintColor được sử dụng cho hình ảnh tab đã chọn. selectedImageTintColor hoàn toàn bị bỏ qua. Không có cách nào để tô màu các ảnh tab không được chọn.

Xem discussion on the Apple Developer Forums về việc này.

Vui lòng gửi bug report with Apple.

+0

Tôi đoán bạn có thể giải quyết vấn đề này bằng cách sử dụng chế độ 'UIImage' với chế độ' UIImageRenderingModeAlwaysOriginal'. – frangulyan

Các vấn đề liên quan