简体   繁体   中英

How can I change the font size in a text view, but not the font style? (light vs. regular) - Swift

I am building an app in which the user types into a textView, and I want the text to get slightly smaller the more the user types so it can fit into the view without needing to move up and down. The problem is that I want the text to be the default System font, but "Light". When I use methods recommended from other questions on here it changes the font properly, but it also changes the font from System Light to System.

textView.font = textView.font.fontWithSize(15)

This is how I am changing the size of the font, I know there are others, this just happens to how I am doing it now. I need a way to change the font size, but also preserve the Light style. Thanks!

edit: I am writing this app in swift.

You can do it like.

textView.font = UIFont(name: textView.font.fontName, size: 18)

Here the font should be as same you defined but you can change the size as you want.

If you want to fix the size then and change the name of font then you can use textView.font.pointSize

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