码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 使用系统的UITabBarController 修改展示的图片大小

时间:2016-08-03 20:17:21      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

1. 设置TabBarItem图片的大小

1
- (void)configurationAppTabBarAndNavigationBar 2 { 3 // 选中的item普通状态图片的大小 4 UIImage *normalImage = self.navigationController.tabBarController.tabBar.selectedItem.image; 5 UIImage *tabNormalImage = [ToolObject createNewImageWithColor:normalImage multiple:1.1]; 6 tabNormalImage = [tabNormalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 7 [self.navigationController.tabBarController.tabBar.selectedItem setImage:tabNormalImage]; 8 // 选中的item选中撞他图片的大小 9 UIImage *selectImage = self.navigationController.tabBarController.tabBar.selectedItem.selectedImage; 10 UIImage *tabSelectImage = [self createNewImageWithColor:selectImage multiple:1.1]; 11 tabSelectImage = [tabSelectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 12 [self.navigationController.tabBarController.tabBar.selectedItem setSelectedImage:tabSelectImage]; 13 self.navigationController.tabBarController.tabBar.tintColor = [UIColor colorWithRed:0.11f green:0.61f blue:0.97f alpha:1.00f]; 14 self.navigationController.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0.85f green:0.85f blue:0.85f alpha:1.00f]; 15 }
2.图片放大或压缩处理 ,图片放大倍数 0 ~ 2 之间 ,0~1 缩小图片,1~2 放大图片 

1
/** 2 * 根据image 返回放大或缩小之后的图片 3 * 4 * @param image 原始图片 5 * @param multiple 放大倍数 0 ~ 2 之间 6 * 7 * @return 新的image 8 */ 9 + (UIImage *) createNewImageWithColor:(UIImage *)image multiple:(CGFloat)multiple 10 { 11 CGFloat newMultiple = multiple; 12 if (multiple == 0) { 13 newMultiple = 1; 14 } 15 else if((fabs(multiple) > 0 && fabs(multiple) < 1) || (fabs(multiple)>1 && fabs(multiple)<2)) 16 { 17 newMultiple = multiple; 18 } 19 else 20 { 21 newMultiple = 1; 22 } 23 CGFloat w = image.size.width*newMultiple; 24 CGFloat h = image.size.height*newMultiple; 25 CGFloat scale = [UIScreen mainScreen].scale; 26 UIImage *tempImage = nil; 27 CGRect imageFrame = CGRectMake(0, 0, w, h); 28 UIGraphicsBeginImageContextWithOptions(image.size, NO, scale); 29 [[UIBezierPath bezierPathWithRoundedRect:imageFrame cornerRadius:0] addClip]; 30 [image drawInRect:imageFrame]; 31 tempImage = UIGraphicsGetImageFromCurrentImageContext(); 32 UIGraphicsEndImageContext(); 33 return tempImage; 34 }

这样就可以修改选中状态和普通状态下的TabBarItem 图片的大小 ,是不是很简单呢,不足之处,还请大家多多指教

iOS 使用系统的UITabBarController 修改展示的图片大小

标签:

原文地址:http://www.cnblogs.com/missCH/p/5734142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!