iphone - 背景可变 View 的透明 UITabBarController

标签 iphone objective-c ios uiview uitabbarcontroller

我想要一个 UITabBarController,它的 alpha 为 0.5,其透明度允许您在后台看到一个 View 。背景 View 必须可访问且可更改。

我可以使用此技术添加背景:https://gist.github.com/1157542

它是一个Category,它向UITabBarController 添加一个 subview ,并将 subview 发送到后面。但是,因为它是一个类别,所以我不能使 subview 成为一个属性。所以我真的无法访问它。

有没有办法使这个背景 View 更加灵活和易于访问?所以我可以,例如,从任何标签栏 Controller 的 View Controller 轻松地向它添加其他 subview ?

最佳答案

您应该子类 UITabBarController 而不是类别。这将使您可以更好地控制对象。这是一个子类的示例。

// MPCustomTabBar.h
@interface MPCustomTabBar : UITabBarController
- (void) setBackgroundImage:(UIImage *)image;
@end

// MPCustomTabBar.m
@interface MPCustomTabBar

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

@end

现在你可以做你想要的所有定制,通过这样的事情分配和初始化你的新子类:

MPCustomTabBar *bar = [[MPCustomTabBar alloc] init];

关于iphone - 背景可变 View 的透明 UITabBarController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11060442/

相关文章:

iphone - UITableView 中的自定义 header 描述

ios - TableView :didSelectRowAtIndexPath/popViewControllerAnimated do not work

ios - 从 iOS SDK 更改帖子默认受众

iPhone MapView将第一个和最后一个注释放在前面

iphone - 遍历 View : Objective-c 中的特定类

objective-c - 如何控制 iPhone 屏幕上的单个像素?

iphone - paymentWithProductIdentifier 的替代解决方案是什么?

ios - 如何在 Modal View presentation swift iOS 中添加动画延迟

iphone - 在 iOS 5 上阻止 AirPlay 镜像

iphone - 加载页面时的 uiactivityindicator