iOS 使用系統的UITabBarController 修改展示的圖片大小

來源:互聯網
上載者:User

標籤:

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 修改展示的圖片大小

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.