2012-08-15 59 views

回答

45

我假設你指的是佈局情節提要/ IB。要獲取圖像的原始大小,只需選擇圖像,然後在鍵盤上按命令 + =。在重新調整大小時,按比例重新調整大小並按住Shift鍵。

+0

偉大的捷徑!有沒有辦法將圖像設置爲原始大小的一半(對於@ 2x視網膜圖像)? – zakdances 2012-08-15 10:26:50

+0

除非你做一些不尋常的事情,否則你不需要考慮視網膜分辨率。 iOS會自動以正確的大小替換@ 2x圖像。只需使用IB中的非視網膜圖像即可。 – 2012-10-17 17:13:48

+0

這是一個很棒的倍頻程序,謝謝。 – 2013-01-28 15:24:42

1

使用contentMode

 imageView.contentMode = UIViewContentModeScaleAspectFit; 

編輯: 我剛纔看到你似乎要調整imageViews尺寸的圖像....不同,那麼

2

你爲什麼不設置代碼中你的uiimageview的大小? 這裏有您需要做什麼......

//get the Image 
UIImage *img = [UIImage imageNamed:@"img.png"]; 

CGFloat x = img.origin.x; 
CGFloat y = img.origin.y; 
CGFloat width = img.size.width; 
CGFloat height = img.size.height; 
imageView.frame = CGRectMake(x, y, width, height); //imageView is your uiimageview's reference 
+0

有沒有辦法通過故事板/ IB界面做到這一點? – zakdances 2012-08-15 09:43:18

+0

不知道,因爲我現在沒有我的Mac。我不認爲你可以改變IB/Storyboard的大小。因爲在調用viewDidLoad方法之前連接到網點實際上並沒有完成,所以如果在調用此方法之前嘗試訪問imageview,仍然會看到nil。 – Humayun 2012-08-15 09:53:08

-3

這是我做過什麼:

imageView.clipsToBounds = YES; 
[imageView setContentMode: UIViewContentModeScaleAspectFit]; 

這是爲我工作。

相關問題