[英]How to change font size in the app on button click using React native
In my react native application I need to add + and - buttons in settings screen to increase or decrease the font size in the entire app when we click on those buttons from settings screen.Any help would be appreciated.在我的本机反应应用程序中,我需要在设置屏幕中添加 + 和 - 按钮,以在我们从设置屏幕中单击这些按钮时增加或减小整个应用程序中的字体大小。我们将不胜感激。
one way to make this is to create a state and update the fontsize
on style一种方法是创建一个
fontsize
并更新样式的字体大小
example:例子:
const [fontSize, setFontSize] = useState(14);
return (
<p style={{fontSize: `${fontSize}px`}}>
My text
</p>
<button onChange={() => setFontSize(fontSize + 1)}>More</button>
<button onChange={() => setFontSize(fontSize - 1)}>Less</button>
);
to make this you can set this fontSize
at top level.为此,您可以在顶层设置此
fontSize
。
another way to make this is add any CSS lib and set the same state in a global CSS using the *
on css另一种方法是添加任何 CSS 库并使用 css 上的
*
在全局 CSS 中设置相同的 state
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.