Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6372955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:18:14+00:00 2026-05-25T01:18:14+00:00

I have a UIView subclass on which the user can add a random CGPath.

  • 0

I have a UIView subclass on which the user can add a random CGPath. The CGPath is added by processing UIPanGestures.

I would like to resize the UIView to the minimal rect possible that contains the CGPath. In my UIView subclass, I have overridden sizeThatFits to return the minimal size as such:

- (CGSize) sizeThatFits:(CGSize)size {
    CGRect box = CGPathGetBoundingBox(sigPath);
    return box.size;
}

This works as expected and the UIView is resized to the value returned, but the CGPath is also “resized” proportionally resulting in a different path that what the user had originally drawn. As an example, this is the view with a path as drawn by the user:

Path as drawn

And this is the view with the path after resizing:

enter image description here

How can I resize my UIView and not “resize” the path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:18:15+00:00Added an answer on May 25, 2026 at 1:18 am

    Use the CGPathGetBoundingBox. From Apple documentation:

    Returns the bounding box containing all points in a graphics path. The
    bounding box is the smallest rectangle completely enclosing all points
    in the path, including control points for Bézier and quadratic curves.

    Here a small proof-of-concept drawRect methods. Hope it helps you!

    - (void)drawRect:(CGRect)rect {
    
        //Get the CGContext from this view
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        //Clear context rect
        CGContextClearRect(context, rect);
    
        //Set the stroke (pen) color
        CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    
        //Set the width of the pen mark
        CGContextSetLineWidth(context, 1.0);
    
        CGPoint startPoint = CGPointMake(50, 50);
        CGPoint arrowPoint = CGPointMake(60, 110);
    
        //Start at this point
        CGContextMoveToPoint(context, startPoint.x, startPoint.y);
        CGContextAddLineToPoint(context, startPoint.x+100, startPoint.y);
        CGContextAddLineToPoint(context, startPoint.x+100, startPoint.y+90);
        CGContextAddLineToPoint(context, startPoint.x+50, startPoint.y+90);
        CGContextAddLineToPoint(context, arrowPoint.x, arrowPoint.y);
        CGContextAddLineToPoint(context, startPoint.x+40, startPoint.y+90);
        CGContextAddLineToPoint(context, startPoint.x, startPoint.y+90);
        CGContextAddLineToPoint(context, startPoint.x, startPoint.y);
    
        //Draw it
        //CGContextStrokePath(context);
    
        CGPathRef aPathRef = CGContextCopyPath(context);
    
        // Close the path
        CGContextClosePath(context);
    
        CGRect boundingBox = CGPathGetBoundingBox(aPathRef);
        NSLog(@"your minimal enclosing rect: %.2f %.2f %.2f %.2f", boundingBox.origin.x, boundingBox.origin.y, boundingBox.size.width, boundingBox.size.height);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIView which I would like to have aligned just above the
If I have a UIView (or UIView subclass) that is visible, how can I
I have a subclass of UIView which draws itself based on data held in
I have a UIScrollView which contains some small UIView subclass. UIScrollView is scroll enabled,
I have a UIView subclass onto which I need to blit a UIImage .
I have a subclass of UIViewController which handles a UIView. The viewcontroller is presented
I have a UIViewController subclass to control a UIView that I want to add
I have a UIView subclass which currently assembles itself completely programatically. It has a
i have created a custom view class which is a subclass of UIview class
I have a UIView subclass which is displayed once i click navigation bar button.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.