Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to get the image size after aspect fit in objectiveC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.37k
    Comment on it

    When we set the aspect fit property of image view then the size of image get reduced because it sets the image according to the aspect ratio.  So if we want to get the size after aspect fit the use the following code-

    In the following code first initialize a image view and set content mode then use the AVMakeRectWithAspectRatioInsideRect property which results the frame of image.


    Here is the code-

    //initialize image view and set the frame 
    UIImageView *imgVW=[[UIImageView alloc]initWithFrame:self.view.frame];
    //add imageview as a subview
     [self.view addSubview:imgVW];
    //create a image
     UIImage *img=[UIImage imageNamed:@"ImageName"];
    //set image in imageview
     [imgVW setImage:img];
    //set content mode of image view
     [imgVW setContentMode:UIViewContentModeScaleAspectFit];
    //get image frame
     CGRect sizeBeingScaledTo = AVMakeRectWithAspectRatioInsideRect(img.size, CGRectMake(0, 0, imgVW.frame.size.width, imgVW.frame.size.height));


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: