2013-03-13 2 views
0

Я хочу, чтобы изменить положение курсора в TextView ...положение курсора TextView изменилось после того, как горизонтальной линии

enter image description here

enter image description here

// NoteView объективный класс _c его супер класс 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)]; 
    } 

Я пишу все методы делегата для Textview и ScrollView из Textview Я курсор positon запускает вертикальную линию после .... Я не хорошо выражен, пожалуйста, поймите на основе изображений ... Я хочу положение курсора .. Я хочу установить TextView с помощью приложения для заметки в iPhone. Я добавляю Textview в ViewController, все работает хорошо, но позиция начала координат курсора ... Я хочу, чтобы позиция курсора всегда была горизонтальной. ........ Попробуйте дать решение на основе изображений ..

+0

is page image является фоном вашего текста или его представлением, содержащим textview – Dilip

+0

нет, я добавил изображение на текстовое изображение, например self.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @ "PaperNoRules_300X462"]]; – user1997077

+0

self mean textview ... – user1997077

ответ

0

Сделайте это, как показано на рисунке.

enter image description here

Здесь вы должны установить позицию вашего TextView в вашей ВК, так что будет после горизонтальной линии.

+0

Мне нужно положение курсора после вертикальной линии – user1997077

+0

, пожалуйста, обратите внимание на код один раз .... – user1997077

+0

Для этого вам нужно разместить свое текстовое изображение в качестве позиции, которую линия будет устанавливать с помощью вертикальной линии. а также ваша линия страниц будет достаточно большой, как ваша строка текста. – Dilip

Смежные вопросы