2

As I know Apple's TextKit not support NSTypesetter(which can set write direction top to bottom), but my language (Traditional mongolian) should be written top to bottom. So I want to customize the UITextView with subclassing and have done a simple demo as bellow(rotate UITextView as M_PI/2).

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.height, frame.size.width)];
    if (self) {
        CGAffineTransform transform = CGAffineTransformRotate(self.transform, M_PI/2);
        CGFloat translate = (frame.size.height - frame.size.width) / 2;
        transform = CGAffineTransformTranslate(transform, translate, translate);
        transform = CGAffineTransformScale(transform, 1, -1);
        self.transform = transform;
    }
    return self;
}

And create a TextView having width=100 & height=200:

ZGTextView *textView = [[ZGTextView alloc] initWithFrame:CGRectMake(110, 20, 100, 200)];
textView.text = @"012345678901234567890123456789012345678901234567890123456789";
[self.view addSubview:textView];

But when run the demo, I found that the text container only used the upper half part of my TextView, even if I init the TextContainer with initWithSize method. I guess it was because of NSLayoutManager automatically set the line length fit to TextView's width (In my test width=100, height=200), But in my ZGTextView it should be fit to TextView's height (vertical line).

Is there any way to customize the NSLayoutManager that it can support draw lines fit to UITextView's height?

user2644464
  • 101
  • 2
  • I found NSLayoutManager defines a NSTextLayoutOrientationVertical on iOS, but I set myTextContainer.layoutOrientation = NSTextLayoutOrientationVertical, the text still be drawn horizontal. – user2644464 Jun 20 '14 at 12:12

0 Answers0