[![带有标签栏控制器的模拟器] [1]] [1]
我创建了tabbar控制器,我想在其中放置图像,但图像变得更大..我在没有使用故事板的情况下以编程方式执行此操作。请帮助我
self.title=@"Speciality";
NSArray *tabs;
UIViewController *tab1 = [tabs objectAtIndex:0];
tab1.tabBarItem.image = [UIImage imageNamed:@"home.png"];
UIViewController *tab2 = [tabs objectAtIndex:1];
tab2.tabBarItem.image = [UIImage imageNamed:@"special.png"];
self.view =singleView;
答案 0 :(得分:0)
试用此代码:
UIImage *image = [UIImage imageNamed:@"image.png"];
self.tabBarItem.image = [self imageWithImage:image scaledToSize:CGSizeMake(30, 30)];
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}