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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:41:06+00:00 2026-05-29T20:41:06+00:00

CGSize cgs = CGSizeMake(250.0, 300.0); UIGraphicsBeginImageContext(cgs); CGRect rectangle = CGRectMake(0,0,cgs.width,cgs.height); UIImage *myImage = [UIImage

  • 0
CGSize cgs = CGSizeMake(250.0, 300.0);
    UIGraphicsBeginImageContext(cgs);    
    CGRect rectangle = CGRectMake(0,0,cgs.width,cgs.height);
    UIImage *myImage = [UIImage imageNamed:@"BMW.jpg"]; 

    [myImage drawInRect:rectangle];    
    [myImage release];

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 5.0);
    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0); 
    CGContextStrokeRect(context, rectangle);

    UIImage *testImg =  UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    [testImg drawAtPoint:CGPointMake(35, 10)];

i want to give gap between image and rectangle borders in which image is drawn, like 5 on left 5 on top and 5 on right but around 30 on bottom because its the space for text that user will write and user can also select that he/she want text on top so in that case top gap will be 30 and bottom gap will be 5. Here is the code it is inside subclass of uiview in drawrect method.

using this code border and image are tightly bound together, i am unable to give gap between border and image. Any idea how can i do that?

Thanks in advance.

enter image description here

  • 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-29T20:41:07+00:00Added an answer on May 29, 2026 at 8:41 pm

    First of all, you have a serious bug. This line is wrong:

    [myImage release];
    

    You don’t own myImage, so you should not release it. You need to read “Memory-Management Rules” in Cocoa Core Competencies. Or you should turn on ARC (automatic reference counting), and then the compiler will take care of releasing things for you. Since ARC is supported since iOS 4.0, you should almost certainly be using it if you’re developing a new app.

    Regarding your image drawing, you just need to modify the rectangle in which you’re drawing the image. For example, you can leave a 5 pixel border on top, left, and right, and a 30 point border on the bottom like this:

    CGRect imageRect = CGRectInset(rectangle, 5, 5);  // move 5 points in on all sides
    imageRect.size.height -= 25;  // make it another 25 points shorter
    [myImage drawInRect:imageRect];
    

    If you want the 30 point border on top, you also need to modify imageRect.origin.y.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code for iPhone app: +(UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { UIGraphicsBeginImageContext(newSize); [image drawInRect:CGRectMake(0, 0, newSize.width,
- (void)viewDidLoad { UIImage *image = [UIImage imageNamed:@moon]; CGSize size = CGSizeMake(256, 256); UIGraphicsBeginImageContextWithOptions(size,
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; CGSize contextSize=CGSizeMake(320,400); UIGraphicsBeginImageContext(self.view.bounds.size); UIGraphicsBeginImageContext(contextSize); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *savedImg
I have the following method in UIImageManipulation.m : +(UIImage *)scaleImage:(UIImage *)source toSize:(CGSize)size { UIImage
In this code CGRect contextRect = self.bounds; will refer which bound? rectangle, imageRect, or
I tried to use BarButton but this is wrong: CGSize thumbSize = CGSizeMake(30.0, 30.0);
Apple CoreGraphics.framework , CGGeometry.h : CG_INLINE bool __CGSizeEqualToSize(CGSize size1, CGSize size2) { return size1.width
The CGSize returned by sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: contains always the same height. Why is that, and
I'm attempting to use sizeWithFont as follows: [commentTextLabel.text sizeWithFont:commentTextLabel.font constrainedToSize:CGSizeMake(commentTextLabel.frame.size.width, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap]; When I
we have this function: CGSize size = [cell.textLabel.text sizeWithFont:cell.textLabel.font constrainedToSize:CGSizeMake(cellWidth, FLT_MAX)]; Can we use

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.