gpt4 book ai didi

iphone - 使 UItabbar 透明

转载 作者:行者123 更新时间:2023-12-03 21:02:04 26 4
gpt4 key购买 nike

所以我的标签栏中有两个标签栏项目,每个项目都有一个带圆角的图像,圆角位于它们相遇的位置,如图所示。我试图将选项卡栏的背景图像设置为透明,而不是如您所见的黑色,但到目前为止,我一直遇到一些不想透明的 View 。这是我目前正在使用的:

[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"transparent"]]];

我也尝试了下一段代码,但没有成功。

[tabBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"transparent"]]];
for(UIView *v in tabBar.subviews)
{
if(v.class == NSClassFromString(@"_UITabBarBackgroundView")||v.class == NSClassFromString(@"UITabBarButton"))
{
[v setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"transparent"]]];
}
for(UIView *vc in v.subviews)
{
[vc setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"transparent"]]];
}
}

有什么建议吗?我怎样才能找到该 View 并使其透明?

tabbar too tabbar

最佳答案

您可以为此实现一个类别,扩展UITabBarController,例如:

UITabBarController+TransparentBackground.h

@interface UITabBarController (TransparentBackground) 
- (void) setBackgroundImage:(UIImage *)image;
@end

UITabBarController+TransparentBackground.m

#import "UITabBarController+TransparentBackground.h"
@implementation UITabBarController (TransparentBackground)

- (void) setBackgroundImage:(UIImage *)image
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
imageView.backgroundColor = [UIColor colorWithPatternImage:image];
[self.view addSubview:imageView];
[self.view sendSubviewToBack:imageView];
[self.view setOpaque:NO];
[self.view setBackgroundColor:[UIColor clearColor]];
}

@end

在您的 AppDelegate.m 文件中添加 #import "UITabBarController+TransparentBackground.h"

在您的 AppDelegate.mdidFinishLaunchingWithOptions 方法中,添加以下两行(在顶部):

[tabBarController setBackgroundImage:[UIImage imageNamed:@"CustomTabBarBackground.png"]];
[tabBarController.view setNeedsDisplay];

希望你按照所说的去做,让它发挥作用。

有关此内容的更多信息:REFRENCE

编辑

通过编写以下内容将属性添加到您的AppDelegate.h:

@property(非原子,保留)IBOutlet UITabBarController *tabBarController;

还在AppDelegate.m文件中执行@sythesize tabBarController;

并将此 IBOutlet 属性XIB 中相应的 TabBarController 连接起来

关于iphone - 使 UItabbar 透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15901870/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com