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

  • Home
  • SEARCH
  • 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 7972311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:50:01+00:00 2026-06-04T07:50:01+00:00

I am using CoreText to draw text in multiple columns (depending on the orientation

  • 0

I am using CoreText to draw text in multiple columns (depending on the orientation of the iPad).

To test, I’ve created an NSMutableString composed of the numbers 100 – 999. This text spans 5 columns, 1 or 2 of which are onscreen (depending on the orientation).

To my main ViewController I’ve added a custom UIScrollView to hold this text, and I want it to be scrollable.

I’ve noticed that the scrollview doesn’t scroll until I set:

[myScrollView setContentMode:UIViewContentModeRedraw];

I do want the scrollView to call drawRect when the iPad is rotated (to adjust the number of columns)!

My issue with this though is that it seems to call drawRect over and over and over … while scrolling (and thus allocates more and more memory, also causing some lag).

I add the UIScrollView to my main viewController like so:

myScrollView = [[CoreTextTestUIView alloc] init];
myScrollView.parentView = self;
if(FACING == @"PU" || FACING == @"PD")
{
    myScrollView.frame = CGRectMake(0,50,768,974);
}
else
{
    myScrollView.frame = CGRectMake(0,50,1024,718);
}
[myScrollView setContentMode:UIViewContentModeRedraw];
[container addSubview:myScrollView];

Again, I want drawRect to be called when the iPad is rotated, so the number of columns can change … BUT I do not want it to call drawRect when I simply try to scroll the UIScrollView.

Can someone help me please?

…

below is the .m for my UIScrollView:

#import "CoreTextTestUIView.h"
#import <CoreText/CoreText.h>

@implementation CoreTextTestUIView

@synthesize parentView;


NSMutableString *testText;



-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        // Initialization code

        //set BG color
        self.backgroundColor = [[UIColor alloc] initWithRed:134 green:166 blue:228 alpha:1.0];

        //UIScrollView Stuff
        //self.delegate = self;
        self.scrollEnabled = YES;
        self.pagingEnabled = YES;
        self.userInteractionEnabled = YES;
        [self becomeFirstResponder];
        self.showsVerticalScrollIndicator = NO;
        self.showsHorizontalScrollIndicator = NO;
        self.bounces = NO;
        self.alwaysBounceHorizontal = YES;
        self.alwaysBounceVertical = NO;

        //generate long text
        testText = [[NSMutableString alloc] initWithString:@""];
        for(int i = 100; i < 1000; i++)
        {
            [testText appendString:[NSString stringWithFormat:@"%i ",i]];
        }

        self.alpha = 0.0;
        [self fadeIn];
    }
    return self;
}



-(void)fadeIn
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];  
    [UIView setAnimationDelegate:self]; 
    //[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];  
    self.alpha = 1.0;
    [UIView commitAnimations];
}



// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
-(void)drawRect:(CGRect)rect
{

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",testText]];

    //set font
    CTFontRef helvetica = CTFontCreateWithName(CFSTR("Helvetica"), 40.0, NULL);
    [string addAttribute:(id)kCTFontAttributeName
                   value:(id)helvetica
                   range:NSMakeRange(0, [string length])];


    //layout master
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string);

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

    int textPos = 0;
    int columnIndex = 0;

    //how many columns? (orientation dependent)
    float howManyColumns;
    if(parentView.FACING == @"PU" || parentView.FACING == @"PD")
    {
        howManyColumns = 1.0;
    }
    else
    {
        howManyColumns = 2.0;
    }

    //create columns in loop
    while(textPos < [string length])
    {
        NSLog(@"column started");

        //column form
        CGMutablePathRef columnPath = CGPathCreateMutable();
        CGPathAddRect(columnPath, NULL, 
                      CGRectMake((self.bounds.size.width/howManyColumns*columnIndex), 0, 
                                 (self.bounds.size.width/howManyColumns),
                                 self.bounds.size.height));

        //column frame
        CTFrameRef columnFrame = CTFramesetterCreateFrame(framesetter, 
                                                             CFRangeMake(textPos, 0),
                                                             columnPath,
                                                             NULL);

        //use the column path
        CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(textPos, 0), columnPath, NULL);
        CFRange frameRange = CTFrameGetVisibleStringRange(frame);

        //draw
        CTFrameDraw(columnFrame, context);

        //cleanup
        CFRelease(columnFrame);
        CGPathRelease(columnPath);

        textPos += frameRange.length;
        columnIndex++;
    }

    //set scrollView content size
    int totalPages = (columnIndex+1)/howManyColumns;
    self.contentSize = CGSizeMake(totalPages*self.bounds.size.width, self.frame.size.height);

    //release
    CFRelease(framesetter);
    [string release];
}



-(void)dealloc
{
    [super dealloc];

    [parentView release];
    [testText release];
}


@end
  • 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-04T07:50:02+00:00Added an answer on June 4, 2026 at 7:50 am

    Looking at this, I can’t see where you are setting the contentSize of your scrollView. If you do not set the contentSize of your scrollView, scrolling will not be enabled, and you will only see what fits within the current area of the scrollView. Also, if your text is static in a configuration, consider optimizing out some of the redrawing that is occurring and add it to a subview of the scrollView.

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

Sidebar

Related Questions

I am using CoreText to render multiple columns of text. However, when I set
I am using CoreText on the iPhone to get italic text in a UIScrollView.
Using monotouch, I'm try to display a core text element over multiple lines. The
I want to use core text to draw string that can span over 100
I am using Core Text to draw some text. I would like to get
I'm trying to draw text using Core Text functions, with a line spacing that's
Im using CoreText to display some text, creating framesetter, frames and so, and everything
I'm drawing some text in Mac/iOS cross-platform code using CoreText. I may be using
Using Nunit, I want to be able to write a test fixture that will
I use the following method to draw text on a PDF document (context). Somehow

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.