我在 UIScrollView 中遇到了 UITextView 模糊的问题,所以我创建了一个简单的小应用程序,它只有一个 ScrollView 保持一个视图,而该视图又具有一个 UITextView。下面的代码是我设置它的所有代码。如果放大文字是模糊的。我看过其他关于此的帖子,建议在 UITextView 上设置 contentScaleFactor。但是,也不起作用。另一个建议是确保 UITextField 的框架不在像素之间……您可以在我的示例中看到框架在整个像素上。
因此,我对如何尝试使文本呈现清晰的想法不知所措。
如果有人有任何想法,请告诉我。
谢谢,
彼得
@implementation SIAppDelegate
{
UITextView *textView;
float originalFontSize;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[SIViewController alloc] initWithNibName:@"SIViewController" bundle:nil];
self.window.rootViewController = self.viewController;
//Setting up the scroll view
UIScrollView *scrollView = (UIScrollView *)self.viewController.view;
scrollView.delegate = self;
scrollView.maximumZoomScale = 5;
scrollView.minimumZoomScale = 1;
//Setting up the content view
UIView *view = [[UIView alloc] initWithFrame:scrollView.frame];
view.backgroundColor = [UIColor blueColor];
textView = [[UITextView alloc] initWithFrame:CGRectIntegral(CGRectMake(200, 200, 200, 200))];
textView.text = @"Hello, World";
[view addSubview:textView];
[scrollView addSubview:view];
scrollView.contentSize = CGSizeMake(2000, 2000);
[self.window makeKeyAndVisible];
return YES;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return scrollView.subviews[0];
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
[scrollView.subviews[0] setContentScaleFactor:scale];
textView.contentScaleFactor = scale;
}
@end