iOS: Scaling UITextView with pinching?

后端 未结 5 2077
心在旅途
心在旅途 2020-12-05 03:33

I\'m interested in creating UITextView that is expanding dynamically while typing the text, and scaling as the user pinches the screen(Similar behaviour can be

5条回答
  •  心在旅途
    2020-12-05 03:59

    UITextView is a subclass of UIScrollView and as such you need to do what you do with any scroll view to enable zooming:

    • set the minimum and maximum zoom scale properties
    • set the viewForZooming via the scrollview delegate method

    ... that zooms the entire text view.

    If you only want to zoom the text then you have to perform these steps via a pinch gesture recognizer:

    • retrieve the current attributed string
    • walk through the font ranges and replace the font attribute with a scaled one
    • replace the text in the text view with your modified version
    • probably you also need to set the text selection after setting the text

提交回复
热议问题