Create a border around UIImageView using 8 images

前端 未结 1 443
名媛妹妹
名媛妹妹 2021-01-06 21:13

I have 8 images I made, 4 images for each of the corners, and 4 images for each of the sides of UIImageView. Now, how on Earth do I make them \'come around\' th

相关标签:
1条回答
  • 2021-01-06 21:29

    It is not really what you are asking for but this is the solution closest to what you are trying to do.

    You should take your 8 images and combine them into one single image and then make a resizable image out of that using resizableImageWithCapInsets:resizingMode:.

    The first arguments lets you specify the top, left, bottom and right inset (i.e. the sizes of your images).

    enter image description here

    The second argument determines if the areas are stretched or tiled.

    Stretched
    Stretched border

    Tiled
    Tiled border

    So to use it you would do something similar to

    UIImage *myFullImage = [UIImage imageNamed:@"nameOfTheCombinedImage"];
    UIImage *resizableImage = 
    [myFullImage resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)resizingMode:UIImageResizingModeTile];
    

    (stretched vs tiles images "borrowed" from here)

    0 讨论(0)
提交回复
热议问题