Search code examples
iosfontsscale

ios: scaling font horizontally without rasterising


Android provides a property textScaleX, that allows to scale text horizontally while retaining font height. I use it quite extensively for Android apps (especially for languages which are not as compact as English) and wish to find something similar in ios.

Obviously, I can draw a text to a graphic context and scale it as an image, but this seems to be a rather awkward solution which turns all text items into ImageView-s.

Is there a native way to scale text horizontally? For example there might be an option to create a custom font based on a system font and change a parameter responsible for text width.


Solution

  • You can just scale the UILabel or UITextView that contains the text:

    UILabel *label = ...
    label.transform = CGAffineTransformMakeScale(0.8,1); //reduced size in x direction by 20%
    

    If that is not enough, you could look into NSLayoutManger, there may be something there.