簡體   English   中英

iOS 9.3中的UIImageView如何呈現UIImage?

[英]How UIImageView in iOS 9.3 rendering an UIImage?

在iOS 9.3中,我有一個正方形的UIImageView(例如200x200),我嘗試分配一個帶有cornerRadius的UIImage(1x1像素),並且UIImageView變成一個圓。 我認為問題來自渲染時的UIImageView。

photoImageView.image = [UIImage imageNamed:@"iphone.jpeg"]; // 1px height x 1 px width
photoImageView.contentMode = UIViewContentModeScaleToFill;
// It can fixed with the below code
// photoImageView.image = [[UIImage imageNamed:@"iphone.jpeg"] stretchableImageWithLeftCapWidth:2 topCapHeight:2];
// photoImageView.contentMode = UIViewContentModeScaleAspectFill;
photoImageView.layer.cornerRadius = 20.0;
photoImageView.layer.masksToBounds = YES;

如果我將contentMode更改為ScaleAspectFill或ScaleToFill,或將UIImage(2x2)的大小或iOS版本低於9.3更改,則它的工作原理與我預期的一樣。

http://i.imgur.com/kM36GPW.png

項目: 下載示例項目

紅色:真實結果。 綠色:預期。

有人可以解釋原因嗎? 謝謝。

通過更改拐角半徑值來嘗試

photoImageView.image = [UIImage imageNamed:@"iphone"]; // 1px height x 1 px width
photoImageView.contentMode = UIViewContentModeScaleToFill;
photoImageView.layer.cornerRadius = 5.0;
photoImageView.layer.masksToBounds = YES;

設置masksToBounds = YES

 photoImageView.layer.masksToBounds=YES;

並設置圖像視圖模式“縱橫比填充”或“縱橫比適合”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM