【问题标题】:UIImage stretch only a portionUIImage 只拉伸一部分
【发布时间】:2011-09-19 01:11:08
【问题描述】:

所以,假设我有这个精灵:

mbm
bcb
mbm

每个字母都是一个部分。 (m:边距;b:边框,c:中心)

我想要一个能够重复 b 和 c 的类,只要它需要完成视图,所以我得到这样的东西:

mbbbbbbbbbbbbbm
bcccccccccccccb
bcccccccccccccb
bcccccccccccccb
mbbbbbbbbbbbbbm

有什么东西可以做到这一点吗? 如果它不存在,关于如何实现它的任何想法?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uiimageview uiimage


    【解决方案1】:

    你不能用这种方法实现吗?

    -(UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

    (见Apple UIImage Class Reference

    【讨论】:

    • 我忘了说...就像我说的,这是4个角...该方法只解决了左上角
    • 该方法可以满足您的需求。尽管您只指定了 top 和 left,但它只会将一个像素条拉伸到刚刚超过大写字母的位置。效果是只有中间部分会拉伸。
    【解决方案2】:

    我们可以使用下面的代码拉伸图像:- 这里我们需要 m..m 必须是相同的大小,所以我们拉伸中间部分

    UIImage *image = [UIImage imageNamed:@"img_loginButton.png"];
        UIEdgeInsets edgeInsets;
        edgeInsets.left = 3.0f; //Assume it is the pixel for starting 'm'
        edgeInsets.top = 0.0f;
        edgeInsets.right = 3.0f; //Assume it is the pixel for Ending 'm'
        edgeInsets.bottom = 0.0f;
        image = [image resizableImageWithCapInsets:edgeInsets];
    //Use this image as your controls image
    

    【讨论】:

      猜你喜欢
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 1970-01-01
      相关资源
      最近更新 更多