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 7049873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:04:27+00:00 2026-05-28T03:04:27+00:00

the problem is… I have a path and i create a view in which

  • 0

the problem is…

I have a path and i create a view in which i draw it. View has the same dimension of path. Then, i create a second view in which i override sizeThatFit: method so first view is scaled until all space of second View is full ( that’s my idea about what sizeThatFit: method does! I don’t know if it’s correct ). That’s the code:

 CGRect rect = CGPathGetBoundingBox(objPath);
 CGRect areaPath = CGRectMake(x, y, rect.size.width, rect.size.height);

 FirstView* first = [[FirstView alloc] initWithFrame:areaPath andObjPath:objPath];
 SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(x, y, 200, 200)];
 [second addSubview:first];

In SecondView i have overriden sizeThatFit: method!

I don’t know why it doesn’t work! Path has always same dimension. I would take a path and draw it in a view in which path takes his dimension. So, for example, if a path’s boundingBox is [10,10] and a view is [100,100], i would that path becomes as big as view dimension. How can i do ??

I hope the problem it’s clear enough. Sorry for my english 🙂

This is FirstView.m:

@synthesize objPath;


- (id)initWithFrame:(CGRect)frame andObjPath:(CGMutablePathRef)path {

self = [super initWithFrame:frame];
if (self) {
    // Initialization code.
    objPath = CGPathCreateMutable();
    CGRect rect = CGPathGetBoundingBox(path);       
    CGAffineTransform trans = CGAffineTransformMake(10, 0, 0, 10, self.bounds.size.width, self.bounds.size.height);
    CGPathAddPath(objPath, &trans, path);
    CGRect pathContainer = CGPathGetBoundingBox(path);
    CGPathAddRect(objPath, &trans, pathContainer);
    CGPathCloseSubpath(objPath);
}
return self;
}

- (void)drawRect:(CGRect)rect {
// Drawing code.
CGContextRef current = UIGraphicsGetCurrentContext();

CGContextAddPath(current, objPath);

CGContextSetLineWidth(current, 0.6);
CGContextSetRGBStrokeColor(current, 0xff / 255.0, 0x40 / 255.0, 0x40 / 255.0, 1);
CGContextSetRGBFillColor(current, 0xff / 255.0, 0xc1 / 255.0, 0xc1 / 255.0, 1);

CGContextDrawPath(current, kCGPathFillStroke);
}

EDIT:

If i do

 FirstView* first = [[FirstView alloc] initWithFrame:areaPath andObjPath:objPath];
 SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(x, y, 200, 200)];
 [second addSubview:first];
[first sizeToFit];

and in SecondView.m i override sizeThatFit method, first view is fitted!!! The problem is that path isn’t fitted too!!! It has always the same dimension 🙁

EDIT2

I tried in this way too:

FirstView* first = [[FirstView alloc] initWithFrame:areaPath andObjPath: objPath];
[first setAutoresizingMask:UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleHeight];
[first setContentMode:UIViewContentModeScaleAspectFit];

 SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(x, y, 200, 200)];
second.autoresizesSubviews = YES;
[second setAutoresizingMask:UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleHeight];
[second setContentMode:UIViewContentModeCenter];

[second addSubview:first];

But nothing! It’s very stressful…. :'(

Pls i need help!

  • 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-28T03:04:28+00:00Added an answer on May 28, 2026 at 3:04 am

    Your path has a certain size, so in order to scale that path up or down, you’ll need to apply a transform to the CGContext where you’re drawing. For example, you could figure out the scale by looking at your view’s size and comparing it to your path’s size, then applying that scale to the context:

    // get current context
    
    CGRect pathBoundingBox = CGPathGetBoundingBox(objPath);
    CGFloat scale = MIN(self.bounds.size.width/pathBoundingBox.size.width,
                        self.bounds.size.height/pathBoundingBox.side.height);
    
    CGContextScaleCTM(current, scale, scale);
    
    // draw path
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have an address field from an Access database which has been converted
Problem Description: We have a service which has applications for main mobile OS’s. We
Problem: I have a large database table (~500k records) which has a list of
Problem I have timestamped data, which I need to search based on the timestamp
PROBLEM: I have a Child class which uses DataContractSerialization and raises a Changed event
Problem I have a protobuf message definition with a MessageType field, which is an
Problem Why would compiling a program which has an int main(void) main function differ
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
Problem: Given a list of strings, find the substring which, if subtracted from the

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.