汉字可以横向和纵向查看。我想让用户有两种选择。如何在 iPhone View 中完成此操作?
例如
+-------------------------+ +-------------------------+
| Hello, I am a newbie. | | b a H |
| | | i m e |
| | | e l |
| | ---> | . a l |
| | | o |
| | | n , |
| | | e |
| | | w I |
+-------------------------+ +-------------------------+
最佳答案
嗨“哦哦” 没有这样的方法或属性可以实现这一点,但是通过 jugad(本地词)技术可以实现。 在下面的代码中,我假设 myLabel 是 UILabel 的一个对象,它以所需的形式显示文本,其中文本取自 myTextField (UITextField 的一个对象)。
CGFloat height= myLabel.font.lineHeight;
int lineCount = myLabel.frame.size.height/height;
float temp = [myTextField.text length]*1.0f/lineCount;
int charPerLine = temp;
charPerLine = (temp > charPerLine)?charPerLine+1:charPerLine;
NSString* original = myTextField.text;
NSString* modifiedString = @"";
for (int i =0; i < lineCount; i++)
{
for (int j = charPerLine-1 ; j >=0; j--)
{
NSRange r = NSMakeRange(i+j*lineCount, 1);
if (r.location < [original length]) {
modifiedString =[modifiedString stringByAppendingFormat:@"%@ ",[original substringWithRange:r]];
}
}
modifiedString = [modifiedString stringByAppendingString:@"\n"];
}
myLabel.text = modifiedString;
关于iphone - 如何在iPhone上垂直绘制NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2808825/