セットUIImage
の二つの方法UIImageView
へ:違い=
まず:
self.imageview.image = [UIImage imageNamed:@"clothing.png"];
第二:
self.imageview.layer.contents = (__bridge id _Nullable)([[UIImage imageNamed:@"clothing.png"] CGImage]);
2つの方法の違いは何ですか?
どれが良いですか?
実際、私がしたいことは、UIImageViewで1つのPNGの一部を表示することです。 2つの方法があります。
まず:
UIImage *image = [UIImage imageNamed:@"clothing.png"];
CGImageRef imageRef = CGImageCreateWithImageInRect(image, rect);
self.imageview.image = [UIImage imageWithCGImage:imageRef];
第二:優れている1
self.imageview2.layer.contents = (__bridge id _Nullable)([[UIImage imageNamed:@"clothing.png"] CGImage]);//way2
self.imageview2.layer.contentsRect = rect;
は?どうして?ありがとう!もちろん
最初のオプションはより優れています。 –
'UIImage'の方向が' UIImageOrientationUp'でない場合、別の結果を得ることがあります。 – KudoCC
私の編集を見ることができます。 – AnthoPak