0

I want to change the cursor position in TextView...

enter image description here

enter image description here

// NoteView objective _c class its super class is TextView...

    #import "NoteView.h"

    @implementation NoteView

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

           self.backgroundColor =[UIColor whiteColor];
    self.contentMode = UIViewContentModeRedraw;
            self.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
        }
        return self;
    }


    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (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);

        CGContextSetStrokeColorWithColor(context,[UIColor colorWithRed:0.29804f green:0.12157f blue:0.9f alpha:0.1].CGColor);

        //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);
    }


     //its a view controller class and here i imported NotesView here
    #import "NotesViewController.h"

    @interface NotesViewController ()

    @end

    @implementation NotesViewController


// i load the textView frame  whatever i created class above
    - (void)loadView {
        [super loadView];
      CGSize  result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width*scale, result.height * scale);
if (result.height==1136)
{
    _TextView = [[NoteView alloc] initWithFrame:CGRectMake(29,50,266,430)];
    backgroundView.frame=CGRectMake(10,32,300,450);

}
else
{
    _TextView = [[NoteView alloc] initWithFrame:CGRectMake(29,50,266,340)];
    backgroundView.frame=CGRectMake(10,32,300,360);


}
[self.view addSubview:_TextView];
_TextView.delegate = self;
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(30,40,1,backgroundView.frame.size.height-5)];
lineView.backgroundColor = [UIColor brownColor];
lineView.alpha=0.3;
[self.view addSubview:lineView];
UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(32,40,1,backgroundView.frame.size.height-5)];
lineView1.backgroundColor = [UIColor brownColor];
lineView1.alpha=0.3;
[self.view addSubview:lineView1];

}

    }

    }
// in view did load i set the delegate and code for cursor position
    - (void)viewDidLoad
    {
        [super viewDidLoad];

        // setting delegate here
        _TextView.delegate=self;
        _TextView.editable = YES;    
       [_TextView setSelectedRange:NSMakeRange(10, 0)];
    }

I write all the delegate methods for Textview and ScrollView of Textview I the cursor positon is starts the vertical line after.... I'm not expressed well please understand based on images... I want cursor position... I want to set my Textview with real note application in iPhone.. I add Textview to ViewController all works well but cursor stats starting position... I want to cursor position always horizontal line........ Try to give solution based on the images..

user1997077
  • 119
  • 1
  • 4
  • 11

1 Answers1

0

Do it like this image.

enter image description here

Here you have to set the position of your textview in your VC so it will come after the horizontal line.

Dilip
  • 9,019
  • 4
  • 43
  • 56
  • i want cursor position after vertical line – user1997077 Mar 13 '13 at 15:54
  • for that you have to place your textview as the position that it line will set with the vertical line. and also your page line be large enough as your textview line. – Dilip Mar 13 '13 at 16:00
  • for that i think you have to chage space between the line of the text view i dont know how but you have to check this link – Dilip Mar 13 '13 at 16:14
  • http://stackoverflow.com/questions/3880526/how-to-increase-a-space-between-two-lines-in-multiline-label – Dilip Mar 13 '13 at 16:15
  • http://stackoverflow.com/questions/5494498/how-to-control-the-line-spacing-in-uilabel – Dilip Mar 13 '13 at 16:16