如何更改UITabbar选择的颜色? [英] how to change UITabbar selected color?

查看:94
本文介绍了如何更改UITabbar选择的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此现在发布
,Apple还会拒绝此代码吗?

according to this post for now, Is apple will also reject this code?

以及如何实施Apple批准的内容?

and how to implement what apple will approve?

@interface UITabBar (ColorExtensions)
- (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur;
@end

@interface UITabBarItem (Private)
@property(retain, nonatomic) UIImage *selectedImage;
- (void)_updateView;
@end

@implementation UITabBar (ColorExtensions)
- (void)recolorItemsWithColor:(UIColor *)color shadowColor:(UIColor *)shadowColor shadowOffset:(CGSize)shadowOffset shadowBlur:(CGFloat)shadowBlur
{
        CGColorRef cgColor = [color CGColor];
        CGColorRef cgShadowColor = [shadowColor CGColor];
        for (UITabBarItem *item in [self items])
                if ([item respondsToSelector:@selector(selectedImage)] &&
                    [item respondsToSelector:@selector(setSelectedImage:)] &&
                    [item respondsToSelector:@selector(_updateView)])
                {
                        CGRect contextRect;
                        contextRect.origin.x = 0.0f;
                        contextRect.origin.y = 0.0f;
                        contextRect.size = [[item selectedImage] size];
                        // Retrieve source image and begin image context
                        UIImage *itemImage = [item image];
                        CGSize itemImageSize = [itemImage size];
                        CGPoint itemImagePosition; 
                        itemImagePosition.x = ceilf((contextRect.size.width - itemImageSize.width) / 2);
                        itemImagePosition.y = ceilf((contextRect.size.height - itemImageSize.height) / 2);
                        UIGraphicsBeginImageContext(contextRect.size);
                        CGContextRef c = UIGraphicsGetCurrentContext();
                        // Setup shadow
                        CGContextSetShadowWithColor(c, shadowOffset, shadowBlur, cgShadowColor);
                        // Setup transparency layer and clip to mask
                        CGContextBeginTransparencyLayer(c, NULL);
                        CGContextScaleCTM(c, 1.0, -1.0);
                        CGContextClipToMask(c, CGRectMake(itemImagePosition.x, -itemImagePosition.y, itemImageSize.width, -itemImageSize.height), [itemImage CGImage]);
                        // Fill and end the transparency layer
                        CGContextSetFillColorWithColor(c, cgColor);
                        contextRect.size.height = -contextRect.size.height;
                        CGContextFillRect(c, contextRect);
                        CGContextEndTransparencyLayer(c);
                        // Set selected image and end context
                        [item setSelectedImage:UIGraphicsGetImageFromCurrentImageContext()];
                        UIGraphicsEndImageContext();
                        // Update the view
                        [item _updateView];
                }
}
@end


推荐答案

,如果您使用该代码,Apple 拒绝某个应用。

Yes, Apple will reject an app if you use that code.

我刚才有应用程序拒绝使用私有API调用。特别是_updateView。我使用了与上面完全相同的代码。

I just had an app rejected for using private API calls. Specifically "_updateView". And I used the exact same code as above.

(如果其他人说他们的应用程序被批准使用相同的代码,那只是因为没有检查使用私人API。)

(If other people say that their app got approved with the same code it's just because it wasn't checked for use of private APIs.)

这篇关于如何更改UITabbar选择的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆