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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:22:39+00:00 2026-05-20T22:22:39+00:00

I have a UITextView where the user can create notes and save into a

  • 0

I have a UITextView where the user can create notes and save into a plist file.
I want to be able to show lines just like a normal notebook. The problem I have is
that the text won’t align properly.

The image below explains the problem quite well.

My print screen explains the problem quite well

This is the background I use to create the lines like the Notes.app
enter image description here

This is my code for creating the background for my UITextView:

textView.font            = [UIFont fontWithName:@"MarkerFelt-Thin" size:19.0]; 
textView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"Notes.png"]];

I know that the UIFont.lineHeight property is only available in > iOS 4.x.

So I wonder if there is another solution to my problem?

  • 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-20T22:22:40+00:00Added an answer on May 20, 2026 at 10:22 pm

    You should try and draw your lines programmatically rather than using an image. Here’s some sample code of how you could accomplish that. You can subclass UITextView and override it’s drawRect: method.

    NoteView.h

    #import <UIKit/UIKit.h>
    @interface NoteView : UITextView <UITextViewDelegate> {
    }
    @end
    

    NoteView.m

    #import "NoteView.h"
    
    @implementation NoteView
    
    - (id)initWithFrame:(CGRect)frame {
    
        self = [super initWithFrame:frame];
        if (self) {
            self.backgroundColor = [UIColor colorWithRed:1.0f green:1.0f blue:0.6f alpha:1.0f];
            self.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:19];
        }
        return self;
    }
    
    - (void)drawRect:(CGRect)rect {
    
        //Get the current drawing context   
        CGContextRef context = UIGraphicsGetCurrentContext(); 
        //Set the line color and width
        CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.2f].CGColor);
        CGContextSetLineWidth(context, 1.0f);
        //Start a new Path
        CGContextBeginPath(context);
    
        //Find the number of lines in our textView + add a bit more height to draw lines in the empty part of the view
        NSUInteger numberOfLines = (self.contentSize.height + self.bounds.size.height) / self.font.leading;
    
        //Set the line offset from the baseline. (I'm sure there's a concrete way to calculate this.)
        CGFloat baselineOffset = 6.0f;
    
        //iterate over numberOfLines and draw each line
        for (int x = 0; x < numberOfLines; x++) {
            //0.5f offset lines up line with pixel boundary
            CGContextMoveToPoint(context, self.bounds.origin.x, self.font.leading*x + 0.5f + baselineOffset);
            CGContextAddLineToPoint(context, self.bounds.size.width, self.font.leading*x + 0.5f + baselineOffset);
        }
    
        //Close our Path and Stroke (draw) it
        CGContextClosePath(context);
        CGContextStrokePath(context);
    }
    
    @end
    

    MyViewController.h

    #import <UIKit/UIKit.h>
    #import "NoteView.h"
    @interface MyViewController : UIViewController <UITextViewDelegate> {
    
        NoteView *note;
    }
    
    @property (nonatomic, retain) NoteView *note;
    
    @end
    

    MyViewController.m

    #import "MyViewController.h"
    #import "NoteView.h"
    
    #define KEYBOARD_HEIGHT 216
    
    @implementation MyViewController
    @synthesize note;
    
    - (void)loadView {
        [super loadView];
        self.note = [[[NoteView alloc] initWithFrame:self.view.bounds] autorelease];
        [self.view addSubview:note];
        note.delegate = self;
        note.text = @"This is the first line.\nThis is the second line.\nThis is the ... line.\nThis is the ... line.\nThis is the ... line.\nThis is the ... line.\nThis is the ... line.\n";
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        [note setNeedsDisplay];
    }
    
    - (void)textViewDidBeginEditing:(UITextView *)textView {
        CGRect frame = self.view.bounds;
        frame.size.height -= KEYBOARD_HEIGHT;
        note.frame = frame;
    }
    
    - (void)textViewDidEndEditing:(UITextView *)textView {
        note.frame = self.view.bounds;
    }
    
    - (void)dealloc {
        [note release];
        [super dealloc];
    }
    

    Take a look at Apple’s documentation for Managing the Keyboard, specifically “Moving Content That Is Located Under the Keyboard”. It explains how to listen for NSNotifcations and adjust your views properly.

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

Sidebar

Related Questions

I have a UITextView and I want have two buttons. When the user taps
I have a book app. User choose a book and UITextView show it. Every
I want to have to occasionally insert text into the UITextView text object. For
I have a modal view that with a UITextView, and the user can enter
I have a UITextView, user can write maximum 160 character in the textView. How
I have a UITextView(not editable). When user tries to select text I want to
I have a UITextView. When the user hits the Send key I want to
I'm using UITextView in my application, i want user to enter maximum 5 lines
I have UITextView subviews inside a UITableViewCell . When user taps on the cell
I want to create a text display area (either UILabel or UITextView) in my

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.