2
iOS 프로그래밍의 초보자로서이 질문이 멍청한 것 같으면 죄송합니다. 일부 rect를 그려서 UITextView에 일부 텍스트를 표시합니다. 유일한 문제는 직사각형이 텍스트로 스크롤되지 않을 것입니다. 그들은 단지 거기에 머물러 있습니다. 당신의 도움에 대한drawRect에서 텍스트가 스크롤되지 않습니다.
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setContentMode:UIViewContentModeRedraw];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGRect rectangle = CGRectMake(0,3.5*self.font.lineHeight,self.frame.size.width,self.font.lineHeight);
CGContextAddRect(context, rectangle);
CGContextStrokePath(context);
}
감사 : 여기에 코드입니다.
답변을 주신 Greg에게 감사드립니다. 나는 약간의 테스트를했고 다음 코드가 트릭을 만들었다. 위의 코드는 textView.m에 있지만 다음과 같은 코드가 ViewController.m에 주목하는 것이 :
- (void)viewDidLoad
{
//other inits....
[textView setDelegate:self];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[textView setNeedsDisplay];
}
그래서 위치를 계속 업데이트해야 drawRect를 호출 할 수 있습니까? 많은 자원을 소비하지 않습니까? –