我是 iOS 开发的新手,但为了开始使用垂直蒙古文脚本制作最基本的应用程序,我需要一个垂直的 UITextView
.我还没有找到任何其他蒙古应用程序开发人员共享他们的代码,所以我正在尝试自己制作.蒙古语从上到下书写,从左到右换行,如下图所示:
I'm new to iOS development, but in order start making even the most rudimentary apps using the vertical Mongolian script, I need to have a vertical UITextView
. I haven't found any other Mongolian app developers sharing their code so I am trying to make it myself. Mongolian is written from top to bottom and lines wrap from left to right as is illustrated in the following graphic:
滚动应该是水平的(从左到右).
Scrolling should be horizontal (left to right).
在 previous question 我提出了一个镜像字体以及 UITextView
的旋转和镜像的组合(因为这是我在 Android 中所做的).但是,在阅读 this answer 并进一步研究 iOS 的做事方式(如使用 TextKit
),我想它可能最好从头开始创建像 UIVerticalTextView
这样的东西,而不是弄乱普通的 UITextView
.因为我看到 UITextView
继承自 UIScrollView,我假设我应该继承 UIScrollView
来制作 UIVerticalTextView
.
In a previous question I proposed a combination of a mirrored font and a rotation and mirroring of the UITextView
(because that is what I had done in Android). However, after reading this answer and doing further research into the iOS way of doing things (like using TextKit
), I'm thinking it may be better to just create something like UIVerticalTextView
from scratch rather than messing with the normal UITextView
. And since I see that UITextView
inheirits from UIScrollView, I assume I should subclass UIScrollView
to make the UIVerticalTextView
.
我上面提到的答案是 UIView
的子类,但我在获取时遇到了很多麻烦滚动上班.这是我想继承 UIScrollView
的另一个原因.此外,当方向发生变化时,该解决方案不会重新排列每行中的单词.
The answer I mentioned above subclassed UIView
but I was having a lot of trouble getting scrolling to work. This is another reason I want to subclass UIScrollView
. Also that solution did not relayout the words in each line when there was an orientation change.
我收集了以下部分,但我不知道如何将它们组合在一起:
I've gathered the following pieces but I'm not sure how to put them together:
UIVerticalTextView
处理?UIVerticalTextView - 这将是 UIScrollView
的子类,但需要添加和/或覆盖哪些方法?
UIVerticalTextView
?UIVerticalTextView - This will be a subclass of UIScrollView
but what are the methods that need to be added and/or overridden?
class UIVerticalTextView: UIScrollView {
// Which properties to include?
// - TextStorage
// - TextContainer
// - LayoutManager
// which methods to override?
// which methods to add to give minimal functionality like UITextView?
// - init
// = text
}
这些问题试图将问题分解成更小的部分:
These questions are attempts to break the problem down into smaller pieces:
并尝试不同的方法:
如果你有一个显示文本的字体,最简单的方法是使用普通的 UITextView:
If you have a font that displays your text the easiest way would be to use the normal UITextView:
UITextView *textView = [[UITextView] alloc] init];
textView.transform = CGAffineTransformMakeRotation(-M_PI/2);
textView.text = @"YOUR TEXT HERE";
[textView setBaseWritingDirection:UITextWritingDirectionRightToLeft forRange:[textView textRangeFromPosition:[textView beginningOfDocument] toPosition:[textView endOfDocument]]];
textView
现在将向右滚动而不是向下滚动,我认为这应该发生在蒙古语中?
The textView
will now scroll to the right not down, I assume that is supposed to happen for mongolian?
这篇关于如何通过从 Swift 中的 UIScrollView 子类化来制作垂直 UITextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!