LoginSignup
10
8

More than 5 years have passed since last update.

React Nativeで複数のstyleを適用する

Posted at

私があたったユースケース的には
「H3のText用Styleと、リンクを有効化したっぽいStyleを2つ適用したい」
でした。

一言で言うと「 style={} には配列で複数のスタイルを渡すことができる」です。

このようにします。

App.tsx
<Text style={[styles.textH3, styles.textLink]}>ほげほげ</Text>

//...
const styles = StyleSheet.create({
  textH3: {
    paddingTop: 10,
    paddingBottom: 10,
    fontSize: 20,
    fontWeight: 'bold',
  },
  textLink: {
    color: 'blue'
  }
});

思っていたより簡単でした!

ちなみに(ちょっと注意点)

パラメータは後勝ちのようです。
上記の場合、例えばtextLinkに fontSize: 5 を入力すると、文字サイズが小さくなってしまいます。
注意しましょう!

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8