ios 图片平铺

2018-11-13  本文已影响0人  Mjs

``` -(UIImage*)drawImageAllInBgWithImage:(UIImage*)image Size:(CGSize)size{

    //开启上下文

    UIGraphicsBeginImageContextWithOptions(size, NO, 0);

    CGFloat heightNum = size.height/image.size.height;

    CGFloat widthNum = size.width/image.size.width;

    for (int i=0; i<ceilf(heightNum); i++) {

        for (int j=0; j<ceil(widthNum); j++) {

            [image drawInRect:CGRectMake(j*image.size.width, i*image.size.height, image.size.width, image.size.height)];

        }

    }

    //获取图片

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    //关闭上下文

    UIGraphicsEndImageContext();

    return newImage;

}

上一篇 下一篇

猜你喜欢

热点阅读