美文网首页
ios 图片平铺

ios 图片平铺

作者: Mjs | 来源:发表于2018-11-13 18:13 被阅读0次

    ``` -(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;

    }

    相关文章

      网友评论

          本文标题:ios 图片平铺

          本文链接:https://www.haomeiwen.com/subject/udglfqtx.html