2013-03-13 4 views
0
내가 텍스트 뷰의 커서 위치를 변경하려면

후 변경 ...텍스트 뷰의 커서 위치는 <p><img src="https://i.stack.imgur.com/j5GK5.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/Qptlo.png" alt="enter image description here"></p> <p>// NoteView 목적 _C 클래스</p>는 슈퍼 클래스는 텍스트 뷰입니다 ... 수평선

#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 및 Textview의 ScrollView에 대한 모든 대리자 메서드를 작성합니다. 커서 positon은 세로선을 시작합니다. 이미지를 기반으로 이해하지 못했습니다. 커서 위치를 원합니다. . 내가 Textview를 iPhone에서 실제 노트 응용 프로그램으로 설정하고 싶습니다. ViewController에 Textview를 추가하면 모든 작업이 잘되지만 커서 위치가 시작됩니다 ... 커서 위치를 항상 수평선으로 바꾸고 싶습니다. 이미지를 기반으로 한 솔루션입니다.

+0

는 텍스트 뷰 – Dilip

+0

내가 self.backgroundColor = 같은 텍스트 뷰에 이미지를 부가 더 함유하지 그 페이지 이미지가 텍스트 뷰 또는 뷰의 배경이다 [UIColor colorWithPatternImage [있는 UIImage imageNamed "PaperNoRules_300X462"@]; – user1997077

+0

자체 의미 textview ... – user1997077

답변

0

이미지가 마음에 들었습니다.

enter image description here

여기 당신은 수평선 뒤에 올 것이다 귀하의 VC에서 텍스트 뷰의 위치를 ​​설정해야합니다.

+0

나는 수직선 뒤에 커서 위치를 원한다. – user1997077

+0

한번 코드를 관찰 해보자 .... – user1997077

+0

당신은 textview를 수직선으로 설정하는 위치로 놓아야한다. 또한 페이지 라인이 텍스트 뷰 라인만큼 커야합니다. – Dilip

관련 문제

 관련 문제