开发者

iPhone: keep text looking good after scale transform applied?

I'm applying a scale tr开发者_如何学Goansform to a UIView that draws a number. (The number is literally being drawn with drawInRect; no UILabel in sight.) The scale transform makes the view smaller by quite a bit... say, 80% smaller.

The resulting number looks a little "chunky". Is there a way that I can keep my text looking nice and anti-aliased, the way it's supposed to look?


The problem is your scale simply zooms in on the rendered (bitmap) text which makes it blurry. One way is to change the font size of the text according to the size of the container before you scale it, or even avoid the scale entirely and just change the font size. See this related question.

The results depends on how you scale the view. It may be that simply changing font size is not enough and you need to stretch the rendered text. If that is the case, you'll have to come up with another approach.

I know you're not using a UILabel, but setting myLabel.adjustsFontSizeToFitWidth = YES will to the font size-trick for you in case you decide to go down that path.


My solution:

  lbl.layer.shouldRasterize = YES;
  lbl.layer.rasterizationScale = 0.375f;

set shouldRasterize when store to original size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜