codice attuale:Maschera dimensioni arbitrarie UIImageView con UIImage ridimensionabile maschera
self.backgroundImageView.image = [self.message imageOfSize:self.message.size]; // Random image, random size
UIImage *rightBubbleBackground = [[UIImage imageNamed:@"BubbleRight"]
resizableImageWithCapInsets:BubbleRightCapInsets
resizingMode:UIImageResizingModeStretch];
CALayer *mask = [CALayer layer];
mask.contents = (id)[rightBubbleBackground CGImage];
mask.frame = self.backgroundImageView.layer.frame;
self.backgroundImageView.layer.mask = mask;
self.backgroundImageView.layer.masksToBounds = YES;
Questo non funziona correttamente. Sebbene la maschera sia applicata, il valore rightBubbleBackground
non viene ridimensionato correttamente per adattarsi allo self.backgroundImageView
, anche se è stato impostato il ridimensionamento degli inserimenti cap (BubbleRightCapInsets
).
Immagine originale:
immagine Mascherina (rightBubbleBackground
):
Risultato:
Ho trovato this answer ma funziona solo per immagini simmetriche. Forse potrei modificare quella risposta per il mio uso.
penso 'mask.frame = self.backgroundImageView.layer.frame; 'dovrebbe essere' mask.frame = self.backgroundImageView.layer.bounds; '. L'uso del codice comporterà uno spostamento della maschera se la cornice del livello non è uguale ai limiti. – PowerQian