简体   繁体   中英

How to increase UITextView font size when UITextView's size increases

I am developing an app which has a feature adding TextView dynamically, increasing and decreasing its size when we are dragging it.

I can adjust the text view size according to the number of characters by setting TextView 's content size to TextView 's size.

When dragging the TextView corners, I increase the size of TextView . I can do this successfully.

When I am dragging TextView 's corners, its size is increasing, but font size is not increasing. Is there any way to increase or decrease TextView font size automatically when TextView size increases?

Try the following code hope it helps.i found from the Link.

#define kDefaultFontSize 24.0


if (myTextView.contentSize.height > myTextView.frame.size.height) {
    int fontIncrement = 1;
    while (myTextView.contentSize.height > myTextView.frame.size.height) {
        myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
        fontIncrement++;
    }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM