簡體   English   中英

如何在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM