19
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

React NativeでTextを角丸のボタンっぽい見た目にする

Posted at

React NativeでTextを角丸のボタンっぽくする時に少しハマったのでメモ

まず、borderRadiusで角丸にする方法

<Text
  style={{
    backgroundColor: "lightblue",
    padding: 10,
    borderRadius: 20,
    borderWidth: 1,
    borderColor: "lightblue",
    overflow: "hidden"
 }}
>
  Button
</Text>

overflow: "hidden"をつけるのがポイントです。
こんな感じになります。
スクリーンショット 2018-09-25 11.11.07.png

このままだと横幅いっぱいになってしまうので、文字長に合わせたWidthにするには、親要素にflexDirection: "row"をつけてあげると大丈夫です。

<View style={{ flexDirection: "row" }}>
  <Text
    style={{
      backgroundColor: "lightblue",
      padding: 10,
      borderRadius: 20,
      borderWidth: 1,
      borderColor: "lightblue",
      overflow: "hidden"
    }}
  >
    Button
  </Text>
</View>
スクリーンショット 2018-09-25 11.16.05.png
19
7
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
19
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?