2013-06-29 34 views
0

我想使用resizableImageWithCapInsets方法调整图像大小。但它没有伸展。我也不知道UIEdgeInsetsMake的真正基础。任何人都可以告诉我它是如何工作的。 我使用这个代码:使用resizableImageWithCapInsets创建可流式图像

UIImage *mars = [UIImage imageNamed:@"button.png" ]; 
    UIImage* marsTiled = [mars resizableImageWithCapInsets: 
          UIEdgeInsetsMake(mars.size.height/4.0, 
              mars.size.width/4.0, 
              mars.size.height/4.0, 
              mars.size.width/4.0) 
               resizingMode: UIImageResizingModeStretch]; 

    [containerView addSubview:marsTiled]; 

这里容器视图是UIView的。

image to resize 它看起来像实施后 enter image description here

请帮助。

回答

0

试试这个:

UIImage *rawEntryBackground = [UIImage imageNamed:@"MessageEntryInputField.png"]; 
UIImage *entryBackground = [rawEntryBackground stretchableImageWithLeftCapWidth:13 topCapHeight:22]; 
UIImageView *entryImageView = [[[UIImageView alloc] initWithImage:entryBackground] autorelease]; 
entryImageView.frame = CGRectMake(5, 0, 248, 40); 
entryImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
0

UIEdgeInsets,您可以指定将不会被streched和为此留,因为它是一个区域。在您的情况下,您可能希望将图像拉伸到圆圈的中间,因此必须通过指定topleftbottomleft和的值,从图像的边界到圆圈的中间指定插图。 right。我会建议使用像Photoshop或预览工具和选取框选择功能来确定插图。你也想直接添加一个UIImageView到你的containerView而不是图像。

enter image description here

[image resizableImageWithCapInsets:UIEdgeInsetsMake(20.f, 12.f, 19.f, 19.f)]