2014-02-19 2 views
0

저는 UITextView를 자체 클래스로 가지고 있으며 최대 줄 수를 얻으 려하므로 텍스트가 범위를 벗어나지 않습니다. UITextView는 문자 래핑과 함께 작동하며 항상 래핑 모드로 있어야합니다. 그러나 선 높이 (4.9)는 작동합니다.UITextView의 textContainer 줄 바꿈 및 최대 줄 수가 작동하지 않습니다.

오작동을 일으키는 원인이 무엇인지 확신 할 수 없습니다. 나는 어떤 도움을 주셔서 감사하겠습니다.

CustomTextView.h

#import <UIKit/UIKit.h> 

@interface CustomTextView : UITextView <NSLayoutManagerDelegate> 

@end 

CustomTextView.m

#import "CustomTextView.h" 

@implementation CustomTextView 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) 
    { 
     self.backgroundColor = [UIColor clearColor]; 
     self.font = [UIFont systemFontOfSize:21.0]; 
     self.dataDetectorTypes = UIDataDetectorTypeAll; 
     self.layoutManager.delegate = self; 
     self.tintColor = [UIColor companyBlue]; 
     [self setLinkTextAttributes:@{NSForegroundColorAttributeName:[UIColor companyBlue]}]; 
     self.contentInset = UIEdgeInsetsMake(0.5, 0, 0, 0); 
     self.scrollEnabled = NO; 
     self.textContainer.maximumNumberOfLines = 9; 
     self.textContainer.lineBreakMode = NSLineBreakByCharWrapping; 
    } 
    return self; 
} 

- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect 
{ 
    return 4.9; 
} 

@end 
+0

'self.numberOfLines = 9' 시도해 보셨습니까? 'maximumNumberOfLines'에서 아무 것도 찾을 수 없습니다. – Putz1103

+0

maximumNumberOfLines은 UITextView의 textContainer 속성 – klcjr89

+0

의 속성입니다. 질문에 대답하지 않았습니다. 'self.numberOfLines = 9'을 시도 했습니까? – Putz1103

답변

0

나는 불행하게도 해결하기 위해 다른 줄 바꿈 모드 정착 결국 : 여기

내가 사용하고 코드입니다 이 : 아마도 그것이 주식 메시지 앱처럼 우주 문자를 감싸지 않는 버그가 아니라는 것을 깨달았습니다. 나는 공간을 포함하여 문자를 감싸는 것이 드문 일이라고 생각했습니다.

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) 
    { 
     self.backgroundColor = [UIColor clearColor]; 
     self.font = [UIFont systemFontOfSize:21.0]; 
     self.dataDetectorTypes = UIDataDetectorTypeAll; 
     self.layoutManager.delegate = self; 
     self.tintColor = [UIColor companyBlue]; 
     [self setLinkTextAttributes:@{NSForegroundColorAttributeName:[UIColor companyBlue]}]; 
     self.scrollEnabled = NO; 
     self.textContainerInset = UIEdgeInsetsMake(8.5, 0, 0, 0); 
     self.textContainer.maximumNumberOfLines = 9; 
     self.textContainer.lineBreakMode = NSLineBreakByTruncatingTail; 
    } 
    return self; 
} 
관련 문제