在添加UILabel以缩放UIScrollview问题时,我遇到了一个奇怪的问题。
我正在为缩放的UIScrollview添加两个视图 1. UIImageView 2. UILabelView
这里的代码用于在UIScrollview上添加UIImageView
float recentZoomScaleValue = 4.5;
CGRect rect = CGRectMake(x, y, 150, 150);
UIImageView *signatureImage = [[UIImageView alloc]initWithFrame:rect];
[signatureImage setImage:image];
[signatureImage setFrame:rect];
//resize the frame to avoid the auto zoom
CGRect frame = signatureImage.frame;
frame.size.width /= recentZoomScaleValue;
frame.size.height /= recentZoomScaleValue;
[signatureImage setFrame:frame];
[self addSubView:signatureImage];
[self.scrollview addSubView:signatureImage];
这里的代码用于在UIScrollview上添加UILabel
float recentZoomScaleValue = 4.5;
txtLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 600, self.fontSize)];
[txtLabel setText:@"loganathan is a good boy"];
[txtLabel setFont:[UIFont fontWithName:txtLabel.font.fontName size:self.fontSize]];
[txtLabel setTextColor:[UIColor redColor]];
[txtLabel setBackgroundColor:[UIColor clearColor]];
[txtLabel setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
CGRect frame = signatureImage.frame;
frame.size.width /= recentZoomScaleValue;
frame.size.height /= recentZoomScaleValue;
[txtLabel setFrame:frame];
[self addSubview:txtLabel];
但问题是,当我试图添加自动缩放添加的UILabel视图时。由于标签文字模糊不清。我不知道为什么,问题是什么。我应该使用CATextLayer而不是UILabel吗?任何可能感激的帮助。
由于
答案 0 :(得分:-1)
当zoomScale发生变化时,您必须将contentsScale
设置为正确的值。或者是当前zoomScale的初始值:
动态缩放示例:
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
[yourLabel.layer setContentsScale:scale*[[UIScreen mainScreen] scale]];
[yourLabel.layer setNeedsDisplay];
}