tabbarcontrollerアプリケーションでは、すべての選択解除された画像タブはグレーの色をしています。私はそれを白に変更したいと思います。uitabbarcontrollerのuitabbaritemのグレーの色を変更するには?
助けていただければ幸いです!
tabbarcontrollerアプリケーションでは、すべての選択解除された画像タブはグレーの色をしています。私はそれを白に変更したいと思います。uitabbarcontrollerのuitabbaritemのグレーの色を変更するには?
助けていただければ幸いです!
独自のコントローラを構築する必要があります。 "このクラス[UITabBarController]はサブクラス化を意図していません"というAppleのドキュメントによると、 UITabBarItemのドキュメントでは、タブバーの画像を「タブバーに表示された画像はこの画像から得られた画像」として提供しています。したがって、タブバーに提供する画像は、タブバー画像の「通常の」外観に合うように操作されます。
したがって、いくつかのUIButtonをサブビューとしてUIViewControllerを構築してから、ルックアンドフィール全体をそのように管理できます。
IMHO、これは多くの利益のために多くの仕事のように思えます。
チェックアウトhttps://github.com/xhan/PlutoLandを実行してください。
カスタムPLTabBarController
クラスを使用すると、そこにカスタムTabBarItemsを割り当てることができます。
UITabBarから継承し、drawRectメソッドをオーバーライドすることができます。以下はアイデンティティインスペクタでUITabBarControllerのTabBarのためのカスタムクラスを設定し、それがInterface Builderのに比べて茶色
- (void)drawRect:(CGRect)rect
{
// Drawing code
float baseComponents[] = { 78/255.0, 30/255.0, 0/ 255.0, 1.0 };
// Get current context
CGContextRef context = UIGraphicsGetCurrentContext();
// Fill full rectangle
CGContextSetRGBFillColor(context, baseComponents[0], baseComponents[1], baseComponents[2], baseComponents[3]);
CGContextFillRect(context,rect);
// Draw light line on top
CGContextSetRGBStrokeColor(context, baseComponents[0] + (67/255.0), baseComponents[1] + (67/255.0), baseComponents[2] + (67/255.0), baseComponents[3]);
CGContextMoveToPoint(context, 0, 1);
CGPoint points[] = { CGPointMake(0,1.5),CGPointMake(rect.size.width,1.5) };
CGContextStrokeLineSegments(context, points , 2);
// Create gradient
CGColorSpaceRef myColorspace;
CGGradientRef myGradient;
size_t num_locations = 2;
CGFloat locations[2] = { 0.0, 1.0 };
CGFloat components[8] = { baseComponents[0] + (46/255.0), baseComponents[1] + (46/255.0), baseComponents[2] + (46/255.0), baseComponents[3], // Start color
baseComponents[0] + (21/255.0), baseComponents[1] + (21/255.0), baseComponents[2] + (21/255.0), baseComponents[3] }; // End color
myColorspace = CGColorSpaceCreateDeviceRGB();
myGradient = CGGradientCreateWithColorComponents (myColorspace, components,locations, num_locations);
// Draw gradient
CGContextDrawLinearGradient(context, myGradient, CGPointMake(0, 2), CGPointMake(0,rect.size.height/2), 0);
// Clean up
CGColorSpaceRelease(myColorspace);
CGGradientRelease(myGradient);
}
に着色されているかのサンプルです。