简体   繁体   English

UITextView在缩放以进行输出时隐藏文本

[英]UITextView hides text when scaled for output

I am trying to output a high res version of my iPhone interface. 我正在尝试输出iPhone接口的高分辨率版本。 I am using labels imagesViews and textViews to create the content. 我正在使用标签imagesViews和textViews创建内容。 I am using renderInContext to make a high res image of the main view, and scaling the content to match. 我正在使用renderInContext来制作主视图的高分辨率图像,并缩放内容以使其匹配。 The labels and imageViews seem to work perfectly, but the textView is hiding the text for some when it's scaled an positioned properly. 标签和imageViews看起来完美地工作,但是当适当缩放位置时,textView隐藏了某些文本。

Here is the basic code: 这是基本代码:

UIGraphicsBeginImageContext(CGSizeMake(1536, 2048));
myExportView.frame = CGRectMake(0, 0, 1536, 2048);
[myLabel setFrame:CGRectMake(myLabel.frame.origin.x*4.4232, myLabel.frame.origin.y*4.4232, myLabel.frame.size.width*4.4232, myLabel.frame.size.height*4.4232)];
[myLabel setFont:[UIFont fontWithName:@"Arial" size:myLabel.font.pointSize*4.4232]];
[myTextView setFrame:CGRectMake(myTextView.frame.origin.x*4.4232, myTextView.frame.origin.y*4.4232, myTextView.frame.size.width*4.4232, myTextView.frame.size.height*4.4232)];
[myTextView setFont:[UIFont fontWithName:@"Arial" size:myTextView.font.pointSize*4.4232]];
[[myExportView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);

Here is a visual of the interface and the output with the 640 × 960 interface on the left and my 1536 × 2048 output image on the right (as intended) Note that the label and the textView have scaled properly, but the text in the textView is gone. 这是接口和输出的视觉效果,左侧为640×960接口,右侧为我的1536×2048输出图像(按预期)请注意,标签和textView已正确缩放,但是textView中的文本离开了。

在此处输入图片说明

Here is the project itself if you want to take a look: owolf.net/uploads/StackOverflow/exportTest.zip 如果您想看一下,这里是项目本身:owolf.net/uploads/StackOverflow/exportTest.zip

在此处输入图片说明 UPDATE here is the textView, on the left, scaled up in every way to 4.5 except in the x it's only *2, on the right the x is scaled to 3. Note the text starts to get clipped. 这里的UPDATE是左边的textView,它以各种方式放大到4.5,除了x只是* 2,右边的x缩放到3。请注意,文本开始被剪切。

Any ideas? 有任何想法吗? Help much appreciated 帮助非常感谢

I had some experiment with your code: 我对您的代码做了一些实验:

- (IBAction)export:(id)sender {

    UIGraphicsBeginImageContext(CGSizeMake(1536, 2048));

    myExportView.frame = CGRectMake(0, 0, 1536, 2048);

   [myLabel setFrame:CGRectMake(myLabel.frame.origin.x*4.4232, myLabel.frame.origin.y*4.4232, myLabel.frame.size.width*4.4232, myLabel.frame.size.height*4.4232)];


   [myLabel setFont:[UIFont fontWithName:@"Arial" size:myLabel.font.pointSize*4.4232]];

   [myTextView setFrame:CGRectMake(myTextView.frame.origin.x*4.4232, myTextView.frame.origin.y*4.55, myTextView.frame.size.width*4.4232, myTextView.frame.size.height*4.4232)];
    [myTextView setFont:[UIFont fontWithName:@"Arial" size:myTextView.font.pointSize*4.4232]];

   [[myExportView layer] renderInContext:UIGraphicsGetCurrentContext()];
   UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
   UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);

       // adding for experiment
   UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
   scroll.contentSize = CGSizeMake(1536, 2048);
   [self.view addSubview:scroll];
   [scroll addSubview:myExportView];

   [scroll addSubview:myTextView];
   [scroll addSubview:myLabel];

} }

(I have changed myTextView.frame.origin.y*4.55) (我已经更改了myTextView.frame.origin.y * 4.55)

so it's happen because you use same coefficients, and in result text view offset a little bit above than needed, so text seems hide. 发生这种情况的原因是您使用相同的系数,结果文本视图的偏移量比所需的偏移量高出一点,因此文本似乎是隐藏的。 It hides by uilabel. 它通过uilabel隐藏。 Try experiment with coefficients,in this case out that increase of size is not linear. 尝试用系数进行实验,在这种情况下,尺寸的增加不是线性的。 Good luck! 祝好运!

I ended up using a label for this. 我最终为此使用了标签。 See this thread for the solution: 请参阅此线程以获取解决方案:

Top aligned UILabel, make text stick to top of label view -ios 顶部对齐的UILabel,使文本停留在标签视图的顶部-ios

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM