7

My next project has a requirement to display Japanese text which is displayed top-to-bottom and right-to-left (traditional Japanese writing style). Is it possible to set a UITextViewto layout text in this way? Below is an example of some text written in this way:

 W H
 O E
 R L
 L L
 D O
 ! ,

Also, I need to be able to select it (so UILabel is out). Is this going to turn into a totally custom view?

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • 1
    helps? http://stackoverflow.com/questions/4905500/change-the-uitextview-text-direction/4906808#4906808 – bryanmac Sep 12 '12 at 03:52
  • @bryanmac See my comment on the answer below – borrrden Sep 12 '12 at 05:05
  • I'm surprised that there doesn't seem to be any existing information about this, not even for OS X. Might a `UIWebView` with an appropriate CSS be an option? Searching for [uiwebview tategaki](http://www.google.com/search?ie=utf8&oe=utf8&q=uiwebview+tategaki&nfpr=1) is suggestive, and even brings up some info here on SO. – jscs Sep 12 '12 at 05:34
  • @JoshCaswell It might end up being just that...but I really despise using UIWebView because then all my interaction has to be with Javascript (needs a highlighting system, memos, etc). Currently looking into a PDF based solution. – borrrden Sep 12 '12 at 06:45

5 Answers5

2

The answer, as it turns out, is "no it can't."

So, I built my own using Core Text, which is heavily based on the "SimpleTextInput". The key to this view is adding YES to the kCTVerticalFormsAttributeName key. Luckily enough, the selection logic is there already in the project, it is just not being used. I was easily able to add it by calling the appropriate methods inside a pan gesture (there was some monkey business with CTFrameGetLineOrigins overwriting some of its neighboring memory but I was luckily able to resolve it).

borrrden
  • 33,256
  • 8
  • 74
  • 109
0

Up to now , it seems that there is no such style custom view you want . If I were you , I would convert the typesetting of Japanese text to adapt to traditional Japanese writing style.( perhaps, it is not a good idea,but it is possible )

maybe the text string is "Y U Q M I E A Z V R N J F B W S O K G C X T P L H D".

BTW , are you good at arithmetic coding ?

Carina
  • 2,260
  • 2
  • 20
  • 45
  • I need to be able to select the text within the view so that the user can search the dictionary for a certain highlighted word. That won't be possible unless the selection follows the text. – borrrden Sep 12 '12 at 08:20
  • This is really a problem . As what you said , maybe creating PDF file – Carina Sep 12 '12 at 08:29
-1

for rigth to left

 uiTextView.text = [NSString stringWithFormat:@"\u202B%@",textString];
ganesh manoj
  • 977
  • 10
  • 24
  • Maybe I wasn't clear, but the text flows from top to bottom, and new lines go from right to left. – borrrden Sep 12 '12 at 05:04
  • This doesn't answer the question at all. This just applies the Unicode RTL marker. The characters are supposed to move from top to bottom. – jscs Sep 12 '12 at 18:03
  • I saw the [original version of the question](http://stackoverflow.com/revisions/12380827/1). It explained that the text needs to be arranged from top to bottom, then left to right. The only thing borrrden changed was the example. The problem is the same. Your answer doesn't solve it. – jscs Sep 13 '12 at 07:23
-1

you could try this--

- (void)loadView {
[super loadView];

CGRect frame = CGRectZero;
frame.size = self.view.frame.size;

UITextView* tv = [[UITextView alloc] initWithFrame:frame];
[self.view addSubview:tv];

tv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

tv.text = [_value description];

tv.editable = NO;
tv.dataDetectorTypes = UIDataDetectorTypeAll;

// default font size is too small
tv.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];

[tv release];
}
Jerry Thomsan
  • 1,409
  • 11
  • 9
-1

If you only want to move the text, try

[textViewTest setContentInset:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)];

Where a positive number moves the frame towards the middle, a negative moves it out from the middle.

For example, [textViewTest setContentInset:UIEdgeInsetsMake(-5, 0, 5,0)], will move the text 5 pixels up!

Jerry Thomsan
  • 1,409
  • 11
  • 9
  • 1
    I don't only want to move the text...I want the layout of the text to be completely different than normal. Look at the diagram in the question, the words start at the top right, and go toward the bottom, with the next line starting again on the top to the left of the first line, etc. – borrrden Sep 12 '12 at 12:38