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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:49:36+00:00 2026-06-10T07:49:36+00:00

I am currently drawing text on string, using drawInRect, restricted to a size using

  • 0

I am currently drawing text on string, using drawInRect, restricted to a size using CGRectSize. It is also centred.

[text drawInRect:CGRectMake(0,0,nWidth,nHeight) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];

What I need to find out is the size and offset of the actual drawn text.
Because it is centred, there is a very good chance that there is an X offset before text is drawn.

I’ve seen the command boundingRectWithSize but I think it may not be supported on IOS?

  • 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-06-10T07:49:37+00:00Added an answer on June 10, 2026 at 7:49 am

    Get the size of the text,

    CGSize size = [text sizeWithFont:font constrainedToSize:CGRectMake(0,0,nWidth,nHeight) lineBreakMode: UILineBreakModeWordWrap];
    

    (See documentation)

    Then, since it is centered, the bounds will be

    CGRect bounds = CGRectMake((nWidth - size.width)/2, ..., size.width, size.height);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using the System.Drawing.Graphics.DrawString() method in .Net to draw text on top
Currently, I am using JHotDraw https://sourceforge.net/projects/jhotdraw/ as Figures Drawing Framework in my application. JHotDraw
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
I'm using [NSString drawInRect:] to draw text to a texture and everything works fine
I am currently drawing single colored pixels to my texture in XNA. However, there
I'm currently porting my jruby/java2d Graph Drawing/Layouting application to macruby/cocoa. Therefore I need to
I am currently writing a ruby plugin for a 3d drawing application(written in c
Currently, i'm experimenting with a very simple GUI drawing ... engine (i guess you
I'm trying to make a drawing app and currently working on the line tool
Currently I am using HTML files for parts of my user interface. I display

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.