I want to let the user resize a UILabel with a pinch gesture. Using a CGAffineTransformScale
alone doesn't do the job, because the text in the label becomes blurry when scaled up.
So what I'm doing is actually using the CGAffineTransformScale to just show that its scaling up, saving the frame size, reverting the transform identity, and finalizing the frame size. A simple switcheroo, but it works.
-(void)handlePinch:(UIPinchGestureRecognizer *)recognizer{
if(recognizer.state == UIGestureRecognizerStateBegan){
startingTransform = self.transform;
}
recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
recognizer.scale = 1;
if (recognizer.state == UIGestureRecognizerStateEnded){
CGRect endFrame = self.frame;
self.transform = startingTransform;
self.frame = endFrame;
}
}
The end result of this is a resized frame for the UILabel. However the text does not scale up to fit the label. Also, the property adjustsFontSizeToFitWidth only works for scaling DOWNWARDS, not upwards ( reference ). So what should I do to make my label scale up to fit the frame?
You're onto something already, I think. The adjustFontSizeToFitWidth
property will only adjust the font size down from whatever size it's set to... so what happens if your label's font size is set to something really big? Like vastly, hugely, mindbogglingly big compared to the possible frame size of your label?
add it in scrollview and in scrollview delegzte specify the view for zooming. http://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/viewForZoomingInScrollView :
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.