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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:08:39+00:00 2026-05-31T13:08:39+00:00

I have a snippet of code below that draws a string to a UIView

  • 0

I have a snippet of code below that draws a string to a UIView using CoreText:

- (void) drawRect:(CGRect)rect
{
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)self.text);
    CGMutablePathRef mutablePathRef = CGPathCreateMutable();
    CGPathAddRect(mutablePathRef, NULL, self.bounds);
    CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), mutablePathRef, NULL);

    CGFloat frameHeight = [self calculateHeightForFrame: frameRef];

    //what do I do here to resposition the mutablePathRef?

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CTFrameDraw(frameRef, context); 

    CFRelease(frameRef);
    CGPathRelease(mutablePathRef);
    CFRelease(framesetter);
}

I initialize a frame and frame setter, and attach them to a CGMutablePath. Then I use the CTLine origins from the frame to calculate the height of the text so I can center it vertically.

After this point I’m a little stumped. Is there a way to move the position of the CGMutablePath to a new origin so it will be centered vertically? I tried CGPathMoveToPoint and it didn’t work.

Or do I need to create a brand new CGMutablePath and a brand new frame and frame setter? If so, how do I remove the CGMutablePath? Will it be removed if I release it?

Any hints on an efficient way I could solve this would be great, thanks.

  • 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-31T13:08:39+00:00Added an answer on May 31, 2026 at 1:08 pm

    Once your CGMutablePathRef has been used to create the frame, modifying the path has not effect on the frame. Moreover CGPathMoveToPoint doesn’t move the path itself but is current point, allowing the append new subpaths.

    You can change the position of the text by applying a translation on the context before drawing.

    CGContextTranslateCTM(x, y);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small snippet of code below that I'm running using PellesC .
I have the code snippet below in C++ which basically calculates the pi using
In the code snippet below, I only have 1 element in the XML that
I have a code snippet similar to the one below that I would like
I have a table defined (see code snippet below). How can I add a
I have a snippet of code that I'm working with to filter rows in
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =
In an Activity, I have some snippet of code that fires off a Message:
I have a code snippet written in PHP that pulls a block of text
I have following code snippet that i use to compile class at the run

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.