標籤:
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)multiple10 {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 else20 {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 修改展示的圖片大小