2012-08-01 60 views

回答

0

如果你的泡沫是由一个UIImageView(是的UIView的子类)表示,你可以添加其他的UIImageView为你泡的一个子视图。您将使该子视图的框架与您的泡泡的框架相等,然后将泡泡的clipsToBounds属性设置为YES,以便子视图受限于泡泡。

然后,您可以将子视图的contentMode设置为UIViewContentModeAspectFill,这会将图像拉伸到您的气泡的大小。就像这样:

//After resizing the bubble to the size you want, to this: 
bubbleView.clipsToBounds = YES; 
UIImageView *imageView = [[UIImageView alloc] initWithFrame:bubbleView.frame]; 
imageView.image = theImage; 
imageView.contentMode = UIViewContentModeAspectFill; 
[bubbleView addSubview:imageView];' 
[imageView release]; 
+0

谢谢您的回复。在这种情况下,imageView将覆盖bubbleView,并保持矩形形状。我想要的是使用图像填充气泡,这是一个不规则的形状。 – Steve 2012-08-01 11:46:54

+0

当您将clipsToBounds属性设置为YES时,子视图将被限制为bubbleView的形状,为您提供所需的效果。 – sppalkia 2012-08-01 22:17:05

+0

UIView的所有形状都是矩形。 – Steve 2012-08-02 01:30:48

0

看看BubbleThingie示例应用程序。它可以像您的示例图像一样进行图像遮罩和光泽效果。

enter image description here