简体   繁体   中英

Change font size in textinput react native based on screen size

i want to change fontSize in textinput based on screen width in react native.

i want to make something like this, expected result is the fontSize go smaller when adding numbers to the textInput

演示预期结果

Resources i tried:

React Native Responsive Font Size

https://reactnativeexample.com/responsive-fontsize-based-on-screen-size-of-the-device-in-react-native/

and much more didn't work.

You need to calculate relationship of text and container width together with letter spacing, margin etc.

fontsize = containerWidth / Math.max(text.length, 1) - adjustment

snack example here: https://snack.expo.io/PJeeBTGGe

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