2012-05-18 57 views

回答

5

嘗試將imageview內容模式設置爲aspectfit。

imageView.contentMode = UIViewContentModeScaleAspectFit; 
+0

UIViewContentModeScaleAspectFit適合圖像,並剪切其餘部分。有沒有辦法使圖像適合imageview的大小而不失真? –

+0

嘗試使用Aspectfill來經常在圖像視圖中設置圖像而不失真。 – Ronak

3
UIViewContentModeScaleToFill 
Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeScaleAspectFit 
Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeScaleAspectFill 
Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeRedraw 
Redisplays the view when the bounds change by invoking the setNeedsDisplay method. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeCenter 
Centers the content in the view’s bounds, keeping the proportions the same. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeTop 
Centers the content aligned at the top in the view’s bounds. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeBottom 
Centers the content aligned at the bottom in the view’s bounds. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeLeft 
Aligns the content on the left of the view. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeRight 
Aligns the content on the right of the view. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeTopLeft 
Aligns the content in the top-left corner of the view. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeTopRight 
Aligns the content in the top-right corner of the view. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeBottomLeft 
Aligns the content in the bottom-left corner of the view. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 

UIViewContentModeBottomRight 
Aligns the content in the bottom-right corner of the view. 
Available in iOS 2.0 and later. 
Declared in UIView.h. 
2

設定尺寸後設置contentMode

[imageView setContentMode: UIViewContentModeScaleAspectFit]; 
imageView.frame = CGRectMake(x, y, width, height); 
+0

謝謝,非常有價值的信息。 –

1

我的圖像調整到包含圖像的UIImageView的大小固定的這個問題必須發生。

對我而言,imageView.contentMode = UIViewContentModeScaleAspectFit也沒有設置imageView的框架工作。

方案

我使用從XIB一個UITableViewCell,它有一個的UIImageView。我以編程方式設置了UIImageView的圖像。