我正在开发一个带有TextView的应用程序。
如果您增加字体大小,旋转TextView并将其保存到相册,您将获得像图像一样的白线。
有解决办法吗?
UIView *trueView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 900, 1070)];
[trueView setBackgroundColor:[UIColor clearColor]];
trueView.clipsToBounds =YES;
UITextView *textView2 = [[UITextView alloc]init];
textView2.text = @"abcdefg";
textView2.textContainer.lineFragmentPadding =0;
textView2.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
textView2.autocorrectionType = UITextAutocorrectionTypeNo;
textView2.autocapitalizationType = UITextAutocapitalizationTypeNone;
textView2.userInteractionEnabled = NO;
textView2.textColor = [UIColor blackColor];
textView2.accessibilityLabel =@"0";
textView2.backgroundColor = [UIColor clearColor];
textView2.layer.borderColor = [[UIColor greenColor] CGColor];
textView2.layer.borderWidth = 1.0f;
textView2.textAlignment = NSTextAlignmentLeft;
textView2.font = [UIFont systemFontOfSize:300];
[textView2 setFrame:CGRectMake(6, 415, 895, 369 )];
UIView *textView = [[UIView alloc]initWithFrame:CGRectMake(6, 415, 895, 369)];
[textView addSubview:textView2];
textView2.transform = CGAffineTransformMakeRotation(90);
[trueView addSubview:textView2];
UIGraphicsBeginImageContextWithOptions(CGSizeMake(900, 1070),NO,1);
CGContextRef trueContext = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(trueContext,0, 0);
[trueView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *originalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(originalImage, self, nil, nil);
旋转textView
时需要扩大宽度,因为它会剪裁边缘。只需增加宽度并相应地调整即可。
另一种解决方案是通过设置最小字体大小来自动调整文本大小,使其始终适合,无论大小如何。
请参阅此线程TextView
最小字体大小 UITextField 最小字体大小
需要注意的另一件事是,如果textView只有一行,则最好使用textField
,这将允许您更多地访问截断,最小字体大小和剪辑等内容。