我想在一個UIView中打包一些UIViews如UIButton,UIImageView。 當我嘗試顯示視圖,它沒有顯示在我的RootViewController的:顯示包含其他UIViews的UIView子類
這裏是我的UIView子類的代碼:
#import "Hover.h"
@implementation Hover
- (id)init{
self = [super init];
if (self) {
// Initialization code
UIImage *hover = [UIImage imageNamed:@"Hover.png"];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = hover;
imageView.frame = CGRectMake(0, 0, hover.size.width, hover.size.height);
imageView.alpha = 0.75;
[self addSubview:imageView];
[imageView release];
}
return self;
}
這裏是RootViewController的類:
- (void)viewDidLoad
{
Hover *hover = [[Hover alloc] init];
[self.navigationController.view addSubview:hover];
[hover release];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
「懸停視圖」未顯示!但是,當我將一個UIImageView添加到我的RootViewController時,它可以工作!
您還需要重寫'UIView'的指定初始化是'initWithFrame:方法',以確保您的觀點是正確的初始化。 – Andriy