UI 탭 표시줄의 색조/배경 색상 변경
UI 탐색 모음과 UI 검색 모음에는 모두 tintColor 속성이 있어 두 항목의 색조 색상을 변경할 수 있습니다(놀랍게도, 알고 있습니다).응용 프로그램에서 UI 탭 표시줄에 동일한 작업을 수행하고 싶지만, 이제 기본 검은색에서 변경할 수 있는 방법을 찾았습니다.아이디어 있어요?
iOS 5는 대부분의 UI 요소의 모양을 사용자 지정하기 위한 몇 가지 새로운 모양 방법을 추가했습니다.
모양 프록시를 사용하여 앱의 모든 UIT 탭바 인스턴스를 대상으로 지정할 수 있습니다.
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;
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
저는 최종 답변에 부록이 있습니다.기본 구성이 올바르지만 부분적으로 투명한 색상을 사용하는 요령을 개선할 수 있습니다.기본 그라데이션을 보여주기 위한 것이라고 생각합니다.아, 또한 적어도 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];
이를 위한 간단한 방법은 없습니다. 기본적으로 UIT 탭바를 하위 분류하고 원하는 작업을 수행하기 위해 사용자 지정 도면을 구현해야 합니다.효과를 위해서는 상당한 노력이 필요하지만, 그럴만한 가치가 있을지도 모릅니다.향후 아이폰 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];
또는 App Delegate에서 이 항목을 수행합니다.
[[UITabBar appearance] setBackgroundColor:[UIColor blackColor]];
탭 모음의 선택 취소 아이콘 색상 변경
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
모양을 사용자 지정할 때는 직관적이지 않은 것으로 악명이 높지만, 다음과 같은 유용한 몇 가지 방법이 더 있습니다.
. 광택이 나는 오버레이를 제거하여 더 평평하게 보이도록 하려면 다음을 수행합니다.
tabBar.backgroundColor = [UIColor darkGrayColor]; // this will be your background
[tabBar.subviews[0] removeFromSuperview]; // this gets rid of gloss
. 사용자 지정 이미지를 탭으로 설정하려면바 버튼은 다음과 같은 작업을 수행합니다.
for (UITabBarItem *item in tabBar.items){
[item setFinishedSelectedImage:selected withFinishedUnselectedImage:unselected];
[item setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
}
어디에selected
그리고.unselected
이다UIImage
선택한 개체입니다.만약 당신이 그것들을 평평한 색으로 하고 싶다면, 내가 찾은 가장 간단한 해결책은 그것을 만드는 것입니다.UIView
원하는 대로backgroundColor
그런 다음 그냥 그것을 하나로 만듭니다.UIImage
Quartz Core의 도움으로.나는 다음 방법을 사용합니다.UIView
a를 얻기 위해UIImage
보기의 내용과 함께:
- (UIImage *)getImage {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [[UIScreen mainScreen]scale]);
[[self layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
마지막으로 단추 제목의 스타일을 사용자 정의할 수 있습니다.수행:
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: ];
또 다른 해결책(해킹)은 탭바 컨트롤러의 알파를 0.01로 설정하여 사실상 보이지 않지만 여전히 클릭할 수 있도록 하는 것입니다.그런 다음 Alpha'ed TabBar 아래에 사용자 지정 탭 모음 이미지를 사용하여 기본 창 닙의 하단에 ImageView 컨트롤을 설정합니다.컨트롤러.그런 다음 탭 모음 컨트롤러가 보기를 전환할 때 이미지를 전환하거나 색상을 변경하거나 강조 표시합니다.
그러나 '...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];
}
스위프트 3.0 답변: (바이브하브 가이콰드에서 제공)
탭 모음의 선택 취소 아이콘 색상을 변경하는 경우:
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
언급URL : https://stackoverflow.com/questions/571028/changing-tint-background-color-of-uitabbar
'programing' 카테고리의 다른 글
사용자 지정 PowerShell 모듈을 원격 세션으로 가져오는 방법은 무엇입니까? (0) | 2023.08.09 |
---|---|
Python: 클립보드 없이 Office/Excel 문서에서 내장된 OLE 액세스 (0) | 2023.08.09 |
lodash를 사용하여 Array에서 객체를 찾고 반환하는 방법은 무엇입니까? (0) | 2023.08.09 |
주석을 사용하여 이름별 스프링 빈 자동 배선 (0) | 2023.08.09 |
신속한 코드 실행의 시작점은 무엇입니까? (0) | 2023.08.09 |