문제

uinavigationbar 및 uisearchbar에는 두 항목의 색조 색상 (놀랍게도 알고 있음)을 변경할 수있는 TintColor 속성이 있습니다. 응용 프로그램에서 Uitabbar와 같은 일을하고 싶지만 이제 기본 검은 색에서 변경하는 방법을 찾았습니다. 어떤 아이디어?

도움이 되었습니까?

해결책

나는 Uitabbarcontroller를 서브 클래스하고 개인 수업을 사용하여 작동하게 할 수있었습니다.

@interface UITabBarController (private)
- (UITabBar *)tabBar;
@end

@implementation CustomUITabBarController


- (void)viewDidLoad {
    [super viewDidLoad];

    CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
    UIView *v = [[UIView alloc] initWithFrame:frame];
    [v setBackgroundColor:kMainColor];
    [v setAlpha:0.5];
    [[self tabBar] addSubview:v];
    [v release];

}
@end

다른 팁

iOS 5는 대부분의 UI 요소의 모양을 사용자 정의하기위한 몇 가지 새로운 외관 방법을 추가했습니다.

외관 프록시를 사용하여 앱에서 Uitabbar의 모든 인스턴스를 타겟팅 할 수 있습니다.

iOS 5 + 6의 경우 :

[[UITabBar appearance] setTintColor:[UIColor redColor]];

iOS 7 이상은 다음을 사용하십시오.

[[UITabBar appearance] setBarTintColor:[UIColor redColor]];

외관 프록시를 사용하면 앱 전체의 탭 막대 인스턴스가 변경됩니다. 특정 인스턴스의 경우 해당 클래스의 새로운 속성 중 하나를 사용하십시오.

UIColor *tintColor; // iOS 5+6
UIColor *barTintColor; // iOS 7+
UIColor *selectedImageTintColor;
UIImage *backgroundImage;
UIImage *selectionIndicatorImage;

최종 답변에 대한 부록이 있습니다. 필수 체계는 정확하지만 부분적으로 투명한 색상을 사용하는 트릭을 개선 할 수 있습니다. 나는 그것이 기본 그라디언트를 보여 주도록하기위한 것이라고 가정합니다. 또한, 탭 바의 높이는 최소한 OS 3에서 48이 아닌 49 픽셀입니다.

따라서 그라디언트가있는 적절한 1 x 49 이미지가있는 경우 사용해야하는 ViewDidload의 버전입니다.

- (void)viewDidLoad {

    [super viewDidLoad]; 

    CGRect frame = CGRectMake(0, 0, 480, 49);
    UIView *v = [[UIView alloc] initWithFrame:frame];
    UIImage *i = [UIImage imageNamed:@"GO-21-TabBarColorx49.png"];
    UIColor *c = [[UIColor alloc] initWithPatternImage:i];
    v.backgroundColor = c;
    [c release];
    [[self tabBar] addSubview:v];
    [v release];

}

AddSubview 만 사용하면 버튼이 클릭 가능성이 떨어지므로 대신 클릭 가능성이 떨어집니다.

[[self tabBar] addSubview:v];

사용:

[[self tabBar] insertSubview:v atIndex:0];

이를 수행하는 간단한 방법은 없습니다. 기본적으로 Uitabbar를 서브 클래스하고 원하는 작업을 수행하기 위해 사용자 정의 도면을 구현해야합니다. 그 효과를위한 약간의 노력이지만 그만한 가치가있을 수 있습니다. Apple에 버그를 제출하여 향후 iPhone SDK에 추가 할 것을 권장합니다.

다음은이를위한 완벽한 솔루션입니다. 이것은 iOS5 및 iOS4에서 나와 잘 작동합니다.

//---- For providing background image to tabbar
UITabBar *tabBar = [tabBarController tabBar]; 

if ([tabBar respondsToSelector:@selector(setBackgroundImage:)]) {
    // ios 5 code here
    [tabBar setBackgroundImage:[UIImage imageNamed:@"image.png"]];
} 
else {
    // ios 4 code here
    CGRect frame = CGRectMake(0, 0, 480, 49);
    UIView *tabbg_view = [[UIView alloc] initWithFrame:frame];
    UIImage *tabbag_image = [UIImage imageNamed:@"image.png"];
    UIColor *tabbg_color = [[UIColor alloc] initWithPatternImage:tabbag_image];
    tabbg_view.backgroundColor = tabbg_color;
    [tabBar insertSubview:tabbg_view atIndex:0];
}

iOS 7 :

[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:(38.0/255.0) green:(38.0/255.0) blue:(38.0/255.0) alpha:1.0]];

또한 시각적 욕구에 따라 먼저 설정하는 것이 좋습니다.

[[UITabBar appearance] setBarStyle:UIBarStyleBlack];

바 스타일은 뷰 컨텐츠와 탭 막대 사이에 미묘한 분리기를 넣습니다.

[[self tabBar] insertSubview:v atIndex:0];나를 위해 완벽하게 작동합니다.

나에게는 다음과 같은 탭 바의 색상을 변경하는 것이 매우 간단합니다.

[self.TabBarController.tabBar setTintColor:[UIColor colorWithRed:0.1294 green:0.5686 blue:0.8353 alpha:1.0]];


[self.TabBarController.tabBar setTintColor:[UIColor "YOUR COLOR"];

이 시도!!!

 [[UITabBar appearance] setTintColor:[UIColor redColor]];
 [[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];

배경색으로

Tabbarcontroller.tabBar.barTintColor=[UIColor redcolour];

또는 앱 대의원에서

[[UITabBar appearance] setBackgroundColor:[UIColor blackColor]];

Tabbar의 선택되지 않은 아이콘의 색상을 변경합니다

iOS 10의 경우 :

// this code need to be placed on home page of tabbar    
for(UITabBarItem *item in self.tabBarController.tabBar.items) {
    item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

iOS 10 이상 :

// this need to be in appdelegate didFinishLaunchingWithOptions
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];

기존 답변에는 몇 가지 좋은 아이디어가 있으며, 많은 사람들이 약간 다르게 작동하며, 선택한 내용은 어떤 장치를 대상으로하는지와 달성하려는 목표 종류에 따라 다릅니다. UITabBar 외관을 사용자 정의 할 때는 직관적이지 않지만 다음은 도움이 될 수있는 몇 가지 트릭이 있습니다.

1). 더 평평한 모습을 위해 광택 오버레이를 제거하려는 경우 :

tabBar.backgroundColor = [UIColor darkGrayColor]; // this will be your background
[tabBar.subviews[0] removeFromSuperview]; // this gets rid of gloss

2). 사용자 정의 이미지를 Tabbar 버튼에 설정하려면 다음과 같은 작업을 수행합니다.

for (UITabBarItem *item in tabBar.items){
    [item setFinishedSelectedImage:selected withFinishedUnselectedImage:unselected];
    [item setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
}

어디에 selected 그리고 unselected ~이다 UIImage 당신이 선택한 대상. 당신이 그것들이 평평한 색이되기를 원한다면, 내가 찾은 가장 간단한 솔루션은 UIView 원하는대로 backgroundColor 그런 다음 a로 렌더링하십시오 UIImage 석영 코어의 도움으로. 카테고리에서 다음 방법을 사용합니다 UIView 얻기 위해 UIImage 보기 내용으로 :

- (UIImage *)getImage {
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [[UIScreen mainScreen]scale]);
    [[self layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return viewImage;
}

3) 마지막으로 버튼 타이틀의 스타일을 사용자 정의 할 수 있습니다. 하다:

for (UITabBarItem *item in tabBar.items){
    [item setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                [UIColor redColor], UITextAttributeTextColor,
                [UIColor whiteColor], UITextAttributeTextShadowColor,
                [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
                [UIFont boldSystemFontOfSize:18], UITextAttributeFont,
            nil] forState:UIControlStateNormal];
}

이것은 당신이 약간의 조정을 할 수 있지만 여전히 상당히 제한적입니다. 특히 텍스트가 버튼 내에있는 위치를 자유롭게 수정할 수 없으며 선택/선택한 버튼에 대해 다른 색상을 가질 수 없습니다. 보다 특정한 텍스트 레이아웃을하고 싶다면 UITextAttributeTextColor 명확하고 텍스트를 selected 그리고 unselected 파트 (2)의 이미지.

[v setBackgroundColor ColorwithRed: Green: Blue: ];

또 다른 솔루션 (해킹)은 TabbarController의 알파를 0.01로 설정하여 사실상 눈에 보이지 않지만 클릭 할 수있는 것입니다. 그런 다음 Alpha'ed TabbarController 아래에 사용자 정의 탭 바 이미지를 사용하여 MainWindow NIB 하단에 ImageView 컨트롤을 설정하십시오. 그런 다음 TabbarController가보기를 전환 할 때 이미지, 색상 변경 또는 Hightlight를 교체하십시오.

그러나 '... more'를 잃고 기능을 사용자 정의합니다.

안녕하세요 iOS SDK 4를 사용하고 있으며 두 줄의 코드 로이 문제를 해결할 수 있었으며 다음과 같습니다.

tBar.backgroundColor = [UIColor clearColor];
tBar.backgroundImage = [UIImage imageNamed:@"your-png-image.png"];

도움이 되었기를 바랍니다!

if ([tabBar respondsToSelector:@selector(setBackgroundImage:)]) {
    // ios 5 code here
    [tabBar setBackgroundImage:[UIImage imageNamed:@"image.png"]];
} 
else {
    // ios 4 code here
    CGRect frame = CGRectMake(0, 0, 480, 49);
    UIView *tabbg_view = [[UIView alloc] initWithFrame:frame];
    UIImage *tabbag_image = [UIImage imageNamed:@"image.png"];
    UIColor *tabbg_color = [[UIColor alloc] initWithPatternImage:tabbag_image];
    tabbg_view.backgroundColor = tabbg_color;
    [tabBar insertSubview:tabbg_view atIndex:0];
}

Swift 3.0 답변 : (Vaibhav Gaikwad에서)

Tabbar의 선택되지 않은 아이콘의 색상 변경을 위해 :

if #available(iOS 10.0, *) {
        UITabBar.appearance().unselectedItemTintColor = UIColor.white
    } else {
        // Fallback on earlier versions
        for item in self.tabBar.items! {
            item.image = item.image?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        }
}

텍스트 색상 변경에 대해서만 :

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .normal)

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.red, for: .selected)

Swift 3에서 외관을 사용하여 AppDelegate 다음을 수행하십시오.

UITabBar.appearance().barTintColor = your_color

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top