Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 <code>UITextView</code> and override it's <code>drawRect:</code> method.</p> <p>NoteView.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface NoteView : UITextView &lt;UITextViewDelegate&gt; { } @end </code></pre> <p>NoteView.m</p> <pre><code>#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 &lt; 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 </code></pre> <p>MyViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "NoteView.h" @interface MyViewController : UIViewController &lt;UITextViewDelegate&gt; { NoteView *note; } @property (nonatomic, retain) NoteView *note; @end </code></pre> <p>MyViewController.m</p> <pre><code>#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]; } </code></pre> <p>Take a look at Apple's documentation for <a href="http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html" rel="noreferrer" title="Managing the Keyboard">Managing the Keyboard</a>, specifically "Moving Content That Is Located Under the Keyboard". It explains how to listen for NSNotifcations and adjust your views properly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload