How to display text using Quartz on the iPhone?

I've been trying to display text using a Quartz context, but no matter what I've tried I simply haven't had luck getting the text to display (I'm able to display all sorts of other Quartz objects though). Anybody knows what I might be doing wrong?


-(void)drawRect:(CGRect)rect { // Drawing code CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSelectFont(context, "Arial", 24, kCGEncodingFontSpecific); CGContextSetTextPosition(context,80,80); CGContextShowText(context, "hello", 6); //not even this works CGContextShowTextAtPoint(context, 1,1, "hello", 6); }

-------------Problems Reply------------

Here is a fragment of code that I'm using.

UIColor *mainTextColor = [UIColor whiteColor];
[mainTextColor set];
drawTextLjust(@"Sample Text", 8, 50, 185, 18, 16);


static void drawTextLjust(NSString* text, CGFloat y, CGFloat left, CGFloat right,
int maxFontSize, int minFontSize) {
CGPoint point = CGPointMake(left, y);
UIFont *font = [UIFont systemFontOfSize:maxFontSize];
[text drawAtPoint:point forWidth:right - left withFont:font
minFontSize:minFontSize actualFontSize:NULL

OK, I got it. First off, change your encoding mode to kCGEncodingMacRoman. Secondly, insert this line underneath it:

CGContextSetTextMatrix(canvas, CGAffineTransformMake(1, 0, 0, -1, 0, 0));

This sets the conversion matrix for text so that it is drawn correctly. If you don't put that line in, your text will be upside down and back to front. No idea why this wasn't the default. Finally, make sure you've set the right fill colour. It's an easy mistake to make if you forget to change from the backdrop colour to the text colour and end up with white-on-white text.

Category:iphone Views:0 Time:2008-09-27

Related post

  • display text notification on statusbar of Iphone 2011-08-03

    I need to show some text notification on statusbar of jailbreaked iphone , while my app enter background ,does the SBStatusBarController has any method to do this ?or other solution?thanks ! --------------Solutions------------- SBStatusBarController

  • How do I access the "displayed" text of a select box option from the DOM? 2008-10-10

    Given the following HTML: <select name="my_dropdown" id="my_dropdown"> <option value="1">displayed text 1</option> </select> How do I grab the string "displayed text 1" using Javascript/the DOM? --------------Solutions--------

  • How can I display text beside each radiobutton when loading a radiobutton list from an enumeration? 2009-05-01

    I am loading a radiobutton list from an enumeration (vertically displayed). I need to show text that describes each radiobutton selection. I am loading it in the codebehind. --------------Solutions------------- There's quite a few aspects of the Enum

  • Problem in displaying texts in each cell of the UITableView control on iPhone 2009-06-22

    I display texts in a cell of the UITableView control. Now the texts that I display can be large enough to fit inside one cell width, so it displays the texts on the second line. But it breaks the word in the middle, (like if say "That sounds great, I

  • iMacros: Can I Select Option by display text instead of value? 2009-07-01

    I am looking to automate selecting an item from a list where the generated HTML looks like: <select name="uid_1""> <option value="0">All</option> <option value="1">Option A</option> <option value="2">Option B</o

  • display text with many clickable URLs 2009-12-17

    I'm using custom NSCell in NSTableView similar to: I wish to display text with many clickable URL. can any body throw me in tight direction? I was trying to do something like: http://

  • is there a jquery solution for removing an item from a select dropdown by display text 2010-01-14

    I see a number of examples of removing an item from a select dropdown by the items value ( such as this question ) but is there a way to remove an item from a select dropdown if all I know is the display text? --------------Solutions------------- Try

  • Getting the display text of an object 2010-02-08

    I would like to know whether there is any mechanism to retrieve the display text of an object. As far as I know, there's no direct LSL function for that. Isn't there any property that we can use to extract this information? --------------Solutions---

  • How display text in password field 2010-03-12

    I have the password field on page. I want to display text "Enter password" on screen before entering password but on focus when user enter password it should go back to password type EDIT: I am using Jquery as well so any small jquery solution will d

  • Displaying text on dialog box 2010-03-13

    How to display text on dialog-box? for example - I want to display a countdown timer, should I go with static text control? --------------Solutions------------- Use a static text control and then call the function BOOL SetWindowText( HWND hWnd, LPCTS

  • How to get displayed text from RichTextBox? 2010-05-01

    How to get displayed text in RichTextBox? I mean if RichTextBox is scrolled to the end, I'd like to receive only those lines, which are visible for me. P.S.It'll be enough to get fisrt displayed string --------------Solutions------------- You should

  • How can I know the displayed text in the UILabelView? 2010-05-20

    How can I know the displayed text in the UILabelView? I have a large text and I am going to have 3 uilabels that represent 3 columns of an iPad App like NYTimes one. When I put the large text in the first column (UILabelView) I need to know how much

  • Setting values and display Text in Android Spinner 2010-05-31

    I need help in setting up value and display text in spinner. as per now I am populating my spinner by array adapter e.g mySpinner.setAdapter(myAdapter); and as far as I know after doing this the display text and the value of spinner at same position

  • Access 2007 - Display text fields in drop down list while bundling to an ID 2010-06-01

    in Access 2007 how can I display text fields in drop down list while bundling to an ID? not while selecting (we can do this by plying with the width field. but what I need after selecting? Do we create a hidden field that stores the ID? -------------

  • javascript how to display text when mouse over input text box? 2010-06-08

    How to display text when mouse over an input text box the simplest way (no css, or etc)?? --------------Solutions------------- Put some title and alt attributes on it. <input type="text" title="show this text" alt="show this text" /> Don't have

  • displaying text in case of Low Voting 2010-06-17

    Is there any module in drupal which provides low rating feedback. eg If someone wants to vote a content as <= 2 (out of 5). Before he does so, there will be a pop up window displaying text "Are you sure you want to rate so low?" etc. If there is n

  • Displaying text on a UILabel in digital form? 2010-06-27

    How can we display text in digital format(seven segment display) on a UILabel similar to the way as text is displayed in Digital Clock. --------------Solutions------------- For simple you can also use Apple recommended font. label.font=[UIFont fontWi

  • i want to display text from textfile in text box . how can i do this .. in C# 2010-07-13

    i want to display text from textfile in text box . how can i do this .. in C# Actually i m making text to speech converter in C# .. SO i want to open text file and want show text of that file in my textbox .. here is my code private void button2_Clic

  • How to get the size of the displayed Text in a TextBox 2010-07-13

    I need your help again. I need a way to determine the size of displayed text in a multi-column TextBox to set the Scrollbars property to the correct value. Since it is some sort of enhanced MessageBox what I work on, the size of the MessageBox should

Copyright (C), All Rights Reserved.

processed in 0.072 (s). 11 q(s)