作为第一个Tab,需要设置Title,在init内搞定:
- (id)init {
self = [super init];
if (self) {
[self setTitle:@"图片展示"];
UIImage *img = [UIImage imageNamed:@""];
[[self tabBarItem] setImage:img];
}
return self;
}
self = [super init];
if (self) {
[self setTitle:@"图片展示"];
UIImage *img = [UIImage imageNamed:@""];
[[self tabBarItem] setImage:img];
}
return self;
}
此处未添加图片名称,所以TabBar只显示“图片展示”。
在- (void)viewDidLoad 中添加view add image 代码:
UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(50.0, 50.0, 48.0, 48.0)];
imageview.image = [UIImage imageNamed:@"China.gif"];
[self.view addSubview:imageview];
[imageview release];
imageview.image = [UIImage imageNamed:@"China.gif"];
[self.view addSubview:imageview];
[imageview release];
使用UIImageView添加图片,然后再add至self.view。