Convert CGPoint from CGRect to other CGRect

前端 未结 2 1804
广开言路
广开言路 2021-01-19 21:23

I have placed one label on view and view\'s frame is CGRectMake(0,0,270,203). Now I have to take screen shot of view with CGRectMake(0,0,800,600)

相关标签:
2条回答
  • 2021-01-19 21:55
        +(UIImage*)screenShotOf:(UIView*)view atScale:(CGFloat)scale
        {
            UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, scale);
            [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
            UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    
            UIGraphicsEndImageContext();
    
            return img;
        }
    

    Here You need to adjust the scale property as you needed.

    0 讨论(0)
  • 2021-01-19 22:12

    You could do something like this:

    -(CGPoint) convertPoint: (CGPoint) point fromRect: (CGRect) fromRect toRect: (CGRect) toRect {
        return (CGPoint){
            (toRect.size.width/fromRect.size.width) * point.x,
            (toRect.size.height/fromRect.size.height) * point.y
        };
    }
    
    0 讨论(0)
提交回复
热议问题