我已經編程創建了一個tab控制器。現在如何剪切更大的圖像以適合以編程方式構建的tabBarController中的tabBar圖標。
,我想圖像添加到不同的標籤,我用其中:
self.tabBarItem.image = [UIImage imageNamed:@"Sample_Image.png"];
的問題是Sample_image在尺寸上大於由標籤要求。
所以只是想知道如何剪輯圖像以適應標籤。
我已經編程創建了一個tab控制器。現在如何剪切更大的圖像以適合以編程方式構建的tabBarController中的tabBar圖標。
,我想圖像添加到不同的標籤,我用其中:
self.tabBarItem.image = [UIImage imageNamed:@"Sample_Image.png"];
的問題是Sample_image在尺寸上大於由標籤要求。
所以只是想知道如何剪輯圖像以適應標籤。
Sample_image is larger in size than is required by tab.
嘗試這一段代碼,因爲這將調整所需要的圖像,並用30x30
尺寸(UITabbar
所需尺寸)返回一個UIImage
實例。
UIImage *image = [UIImage imageNamed:@"Sample_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;
}
重命名你的圖像[email protected]
。這稱爲視網膜顯示器的像素倍增。
如果沒有@ 2x iOS不知道它應該應用一個縮放因子,它將按原樣使用,儘管它應該減半。
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:@"[email protected]"]];
在現實中應該有:
Sample_Image PNG(45像素左右)
[email protected] 所以你只能說:
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:@"Sample_Image.png"]];
如果你的圖標不適合在標籤欄中,然後將同一圖像複製到2張圖片資源或3張圖片資源中,而不是1張資源。它會適合,它適用於我
這是爲TabBar背景圖像,我認爲。問題是爲tabBar項目調整背景圖像的大小\ n標籤欄包含多個標籤欄項目 –