[英]what is the best way to Calculate responsive height, width and font-size for both operating system [React Native]?
[英]How to make font-size responsive in react native
由於flex-box不允許以百分比形式更改其字體大小,因此如何根據視圖更改字體大小。 我嘗試使用尺寸,但這沒有用。
您可以使用以下代碼段縮放fontSize:
SCREEN_WIDTH = Dimensions.get('window').width; // get current width
SCALE = 375; // constant, 375 is standard width of iphone 6 / 7 / 8
const scaleFontSize = (fontSize) => {
const ratio = fontSize / SCALE; // get ratio based on your standard scale
const newSize = Math.round(ratio * SCREEN_WIDTH);
return newSize;
}
現在,您可以使用標准fontSize調用scaleFontSize
,它將自動縮放。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.