2014-01-27 5 views
0

약간 이상하게 보일 수 있지만 선명한 배경으로 만드는 사용자 지정 textView가 있습니다. 또한 가로 채색 선을 사용하여 사용자 지정 스크롤보기를 만들고이 scrollview를 textView 아래에 설정합니다. 이유는 내가 처음 text.View에서 선을 추가하지 않는 이유는 (왜냐하면 내가 처음에 해왔 던) top view와 scrollView 사이에 다른 뷰 'sandwhiched'가 있기 때문입니다. 그래서 계층 구조는 다음과 같습니다 : Top ---> UITextView, Middle ---> UIView, Bottom ---> UIScrollView.사용자 지정 UITextView로 사용자 지정 UIScrollView 스크롤

scrollView의 내용 크기가 textView의 것과 같지 않으므로 scrollView 내에서 그려지는 추가 선이 없으므로 bottom scrollview를 textView로 스크롤 할 수없는 것 외에는 완벽하게 작동합니다. . 나는 scrollView의 내용 크기를 textView의 내용 크기로 설정하려고 시도했으나 작동하지 않습니다.

도움과 조언을 보내 주시면 감사하겠습니다. 나는 사용자 정의 스크롤 뷰를 생성하기 위해 사용하고있는 코드를 추가 할 것이다.

코드 :

LineScrollView.h :

#import <UIKit/UIKit.h> 

@interface LineScrollView : UIScrollView 

@end 

LineScrollView.m :

의 ViewController
#import "LineScrollView.h" 

@implementation LineScrollView 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) 
    { 
     self.backgroundColor = [UIColor clearColor]; 
     self.userInteractionEnabled = NO; 
     self.scrollsToTop = NO; 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetStrokeColorWithColor(context, [UIColor colorWithRed:(95.0f/255.0f) green:(197.0f/255.0f) blue:(236.0f/255.0f) alpha:0.8f].CGColor); 
    CGContextSetLineWidth(context, 1.2f); 
    CGContextBeginPath(context); 

    // Below lineHeight value determined using NSLog on my custom textView  

    CGFloat lineHeight = 21.473999; 
    NSUInteger numberOfLines = (self.contentSize.height + self.bounds.size.height)/lineHeight; 

    CGFloat baselineOffset = 1.2f; 

    for (int x = 1; x < numberOfLines; x++) 
    { 
     CGContextMoveToPoint(context, self.bounds.origin.x, (lineHeight+9)*x - baselineOffset); 
     CGContextAddLineToPoint(context, self.bounds.size.width, (lineHeight+9)*x - baselineOffset); 
    } 

    CGContextClosePath(context); 
    CGContextStrokePath(context); 
} 

@end 

: 나는 해결책을 찾아 냈다처럼

#import "TextView.h" 
#import "LineScrollView.h" 

@property (nonatomic, strong) TextView *TextView; 
@property (nonatomic, strong) UIView *sandWhichedView; 
@property (nonatomic, strong) LineScrollView *LineView; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.sandWhichedView = [[UIView alloc]initWithFrame:initWithFrame:CGRectMake(41.5, 35, 278, 58)]; 

    self.TextView = [[TextView alloc] initWithFrame:CGRectMake(41.5, 35, 278, 58)]; 

    self.LineView = [[LineScrollView alloc]initWithFrame:CGRectMake(41.5, 35, 279, 58)]; 

    self.LineView.delegate = self; 

    self.TextView.delegate = self; 

    [self.view addSubview:self.LineView]; 
    [self.view addSubview:self.sandWhichedView]; 
    [self.view addSubview:self.TextView]; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    if (scrollView == self.TextView) 
    { 
     self.LineView.contentSize = self.TextView.contentSize; 
     CGPoint offset = self.TextView.contentOffset; 
     offset.y = self.TextView.contentOffset.y; 
     [self.LineView setContentOffset:offset]; 
    } 
} 

답변

0

가 보이는, I 티 추가하는 걸 잊었 어. 내 사용자 정의 scrollView의 라인 :

self.contentMode = UIViewContentModeRedraw; 

문자 그대로 내 모든 두통을 해결했습니다.

관련 문제