简体   繁体   中英

UITextView hides text when scaled for output

I am trying to output a high res version of my iPhone interface. I am using labels imagesViews and textViews to create the content. I am using renderInContext to make a high res image of the main view, and scaling the content to match. The labels and imageViews seem to work perfectly, but the textView is hiding the text for some when it's scaled an positioned properly.

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.

在此处输入图片说明

Here is the project itself if you want to take a look: 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.

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)

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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