我想要一个 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/