Reputation: 59
I am creating an app which has a UILabel
which can be pinched, rotated. When I pinch in the UILabel
, it gets pixelated. How can I resolve this?
Upvotes: 1
Views: 1855
Reputation: 3081
I got this to work, try it.
CGFloat maxFontSize;
NSString* string = pTextLabel.text;
UIFont* pfont = [UIFont fontWithName:[pTextLabel font].fontName size:600];
[string sizeWithFont:pfont minFontSize:3 actualFontSize:&maxFontSize forWidth:pTextLabel.frame.size.width - 1 lineBreakMode: UILineBreakModeWordWrap];
UIFont* pStampFont = [UIFont fontWithName:[pTextLabel font].fontName size:maxFontSize];
[pTextLabel setFont:pStampFont];
Upvotes: 0
Reputation: 4061
I got this to work, try it.
pinchScale2 = pinchGesture.scale;
pinchScale2 = round(pinchScale2 * 1000) / 1000.0;
if (pinchScale2 < pinchScale1)
{
self.UILabel.font = [UIFont fontWithName:self.UILabel.font.fontName size:(self.UILabel.font.pointSize - pinchScale2)];
}
else
{
self.UILabel.font = [UIFont fontWithName:self.UILabel.font.fontName size:(self.UILabel.font.pointSize + pinchScale2)];
}
pinchScale1 = pinchScale2;
Upvotes: 1
Reputation: 4061
Assuming UILabel
is property of your viewController:
CGFloat pinchScale = pinchGesture.scale;
pinchScale = round(pinchScale * 1000) / 1000.0;
if (pinchScale < 1) {
self.UILabel.font = [UIFont fontWithName:self.UILabel.font.fontName size:(self.UILabel.font.pointSize - pinchScale)];
}
else{
self.UILabel.font = [UIFont fontWithName:self.UILabel.font.fontName size:(self.UILabel.font.pointSize + pinchScale)];
}
Also, set adjustsFontSizeToFitWidth
to YES
Upvotes: 4
Reputation: 1098
You can get the rounded off scale of the pinchgesture by
- (void)pinch:(UIPinchGestureRecognizer *)pinchGesture
{
CGFloat pinchScale = pinchGesture.scale;
pinchScale = round(pinchScale * 1000) / 1000.0;
YourLabel.font = [UIFont fontWithName:@"your font Name" size:Actual Font size+pinchScale];
}
Try this may this help.
Upvotes: 2