# デザインをカスタマイズする Appearance API を使用してモバイルの実装をカスタマイズします。 # iOS > This is a iOS for when platform is ios. View the full page at https://docs.stripe.com/elements/appearance-api/mobile?platform=ios. [mobile Payment Element](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=mobile&platform=ios) は視覚的なカスタマイズをサポートしており、アプリのデザインに合わせてカスタマイズできます。レイアウトの一貫性は保たれますが、[PaymentSheet.Configuration](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Configuration.html) オブジェクトの [appearance](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Configuration.html#/s:6Stripe12PaymentSheetC13ConfigurationV10appearanceAC10AppearanceVvp) プロパティを使用することで、色やフォントなどを変更できます。 1. 最初に[フォント](https://docs.stripe.com/elements/appearance-api/mobile.md#fonts-ios)をカスタマイズします。 1. アプリに合わせて[カラー](https://docs.stripe.com/elements/appearance-api/mobile.md#colors-ios)をカスタマイズします。 1. 角の半径などの[形状](https://docs.stripe.com/elements/appearance-api/mobile.md#shapes-ios)をカスタマイズします。 1. [特定のコンポーネント](https://docs.stripe.com/elements/appearance-api/mobile.md#specific-ui-components-ios)を微調整します。 ![](https://b.stripecdn.com/docs-statics-srv/assets/ios-appearance-before-after-example.ad6a9aad238be9b198e9ebbc77ebe1d4.png) ```swift var configuration = PaymentSheet.Configuration() // The following code creates the appearance shown in the screenshot abovevar appearance = PaymentSheet.Appearance() appearance.font.base = UIFont(name: "AvenirNext-Regular", size: UIFont.systemFontSize)! appearance.cornerRadius = 12 appearance.shadow = .disabled appearance.borderWidth = 0.5 appearance.colors.background = .white appearance.colors.primary = UIColor(red: 36/255, green: 36/255, blue: 47/255, alpha: 1) appearance.colors.textSecondary = .black appearance.colors.componentPlaceholderText = UIColor(red: 115/255, green: 117/255, blue: 123/255, alpha: 1) appearance.colors.componentText = .black appearance.colors.componentBorder = .clear appearance.colors.componentDivider = UIColor(red: 195/255, green: 213/255, blue: 200/255, alpha: 1) appearance.colors.componentBackground = UIColor(red: 243/255, green: 248/255, blue: 250/247, alpha: 1) appearance.primaryButton.cornerRadius = 20 configuration.appearance = appearance let paymentSheet = PaymentSheet(/* ... */, configuration: configuration) ``` ## フォント [font.base](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance/Font.html#/s:6Stripe12PaymentSheetC10AppearanceV4FontV4baseSo6UIFontCvp) を、任意のサイズと太さのカスタムフォントのバリアントに設定し、フォントをカスタマイズします。Mobile Payment Element では、カスタムフォントのフォントファミリーが使用されますが、サイズと太さは自動的に決定されます。 すべてのテキストのサイズを拡大縮小するには、[font.sizeScaleFactor](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance/Font.html#/s:6Stripe12PaymentSheetC10AppearanceV4FontV15sizeScaleFactor12CoreGraphics7CGFloatVvp) を設定します。フォントサイズは、この値で乗算されてから表示されます。これは、カスタムフォントがシステムフォントよりも若干大きいか小さい場合に役立ちます。 ```swift var configuration = PaymentSheet.Configuration() configuration.appearance.font.base = UIFont(name: "CustomFont-Regular", size: UIFont.systemFontSize) configuration.appearance.font.sizeScaleFactor = 1.15 // Increase the size of all text by 1.15x ``` ## カラー モバイルの Payment Element で、[Appearance.Colors](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance.html#/s:6Stripe12PaymentSheetC10AppearanceV6ColorsV) で定義されているカラーカテゴリーを変更することにより、色をカスタマイズします。各カラーカテゴリーは、UI の 1 つ以上のコンポーネントの色を決定します。たとえば、[primary](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance/Colors.html#/s:6Stripe12PaymentSheetC10AppearanceV6ColorsV7primarySo7UIColorCvp) は、**支払う**ボタンと、**このカードを保存**のチェックボックスといった選択された項目の色を定義します。下の図で、各カラーカテゴリーに関連付けられた UI エレメントをご覧いただけます。 ![](https://b.stripecdn.com/docs-statics-srv/assets/ios-appearance-colors.2063c1f71eaa17656639098f3f4d29d6.png) > ダークモードをサポートするには、[init(dynamicProvider:)](https://developer.apple.com/documentation/uikit/uicolor/3238041-init) を使用してカスタムの UIColors を初期化します。 ## 形状 フォントと色の他、Mobile Payment Element 全体で使用されている[角の半径](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance.html#/s:6Stripe12PaymentSheetC10AppearanceV12cornerRadius12CoreGraphics7CGFloatVvp)、[境界線の幅](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance.html#/s:6Stripe12PaymentSheetC10AppearanceV11borderWidth12CoreGraphics7CGFloatVvp)、[シャドウ](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance.html#/s:6Stripe12PaymentSheetC10AppearanceV6shadowAE6ShadowVvp)もカスタマイズできます。 ![](https://b.stripecdn.com/docs-statics-srv/assets/ios-appearance-shapes.ee37fc31111aa78f26af4045a3857468.png) ## 特定の UI コンポーネント 上記のセクションでは、複数の UI コンポーネントにわたり Mobile Payment Element に広く影響を与えるカスタマイズオプションについて説明しています。また、1 次ボタン (たとえば、**支払う**ボタン) 専用のカスタマイズオプションも提供しています。カスタマイズオプションの詳細なリストについては、[Appearance.PrimaryButton](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance/PrimaryButton.html) をご覧ください。 一部の UI コンポーネントのカスタマイズオプションは、他の値よりも優先されます。たとえば、`appearance.primaryButton.cornerRadius` は、`appearance.cornerRadius` の値を上書きします。 > より多くのカスタマイズオプションの提供が必要と思われる場合は、[お知らせください](https://github.com/stripe/stripe-ios/issues/new/choose)。 # Android > This is a Android for when platform is android. View the full page at https://docs.stripe.com/elements/appearance-api/mobile?platform=android. [mobile Payment Element](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=mobile&platform=android) は視覚的なカスタマイズをサポートしており、アプリのデザインに合わせてカスタマイズできます。レイアウトの一貫性は保たれますが、[appearance](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-configuration/index.html#-431946322%2FProperties%2F2002900378) オブジェクトと [PaymentSheet.Configuration](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-configuration/index.html) オブジェクトを作成することで、色やフォントなどを変更できます。 1. 最初に[フォント](https://docs.stripe.com/elements/appearance-api/mobile.md#fonts-android)をカスタマイズします。 1. アプリに合わせて[カラー](https://docs.stripe.com/elements/appearance-api/mobile.md#colors-android)をカスタマイズします。 1. 角の半径などの[形状](https://docs.stripe.com/elements/appearance-api/mobile.md#shapes-android)をカスタマイズします。 1. [特定のコンポーネント](https://docs.stripe.com/elements/appearance-api/mobile.md#specific-ui-components-android)を微調整します。 ![](https://b.stripecdn.com/docs-statics-srv/assets/android-appearance-before-after-example.acf584a69eb99f47fe0b5ffab24818b8.png) ```kotlin // The following code creates the appearance shown in the screenshot aboveval appearance = PaymentSheet.Appearance( colorsLight = PaymentSheet.Colors( primary = Color(red = 36, green = 36, blue = 47), surface = Color.White, component = Color(red = 243, green = 248, blue = 245), componentBorder = Color.Transparent, componentDivider = Color.Black, onComponent = Color.Black, subtitle = Color.Black, placeholderText = Color(red = 115, green = 117, blue = 123), onSurface = Color.Black, appBarIcon = Color.Black, error = Color.Red, ), shapes = PaymentSheet.Shapes( cornerRadiusDp = 12.0f, borderStrokeWidthDp = 0.5f ), typography = PaymentSheet.Typography.default.copy( fontResId = R.font.avenir_next ), primaryButton = PaymentSheet.PrimaryButton( shape = PaymentSheet.PrimaryButtonShape( cornerRadiusDp = 20f ), ) ) // ... paymentSheet.presentWithPaymentIntent( clientSecret, PaymentSheet.Configuration( merchantDisplayName = merchantName,appearance = appearance ) ) ``` ## フォント [typography.fontResId](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-typography/index.html#-786783041%2FProperties%2F2002900378) をカスタムフォントのリソース ID に設定し、フォントをカスタマイズします。モバイルの Payment Element ではカスタムフォントのフォントファミリーが使用されますが、サイズと太さは自動的に決定されます。 テキストのサイズを拡大縮小するには、[typography.sizeScaleFactor](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-typography/index.html#1477076499%2FProperties%2F2002900378) を設定します。Stripe は、フォントサイズを表示する前に、この値をフォントサイズにかけます。この設定は、カスタムフォントがシステムフォントよりもわずかに大きいか小さい場合に便利です。 ```kotlin val appearance = PaymentSheet.Appearance( // …typography = PaymentSheet.Typography.default.copy( sizeScaleFactor = 1.15f, // Increase the size of all text by 1.15x fontResId = R.font.myFont, ), ) val configuration = PaymentSheet.Configuration.Builder("Example, Inc.") // … .appearance(appearance) .build() ``` ## カラー モバイルの Payment Element で、[PaymentSheet.Colors](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-colors/index.html) で定義されているカラーカテゴリーを変更して、色をカスタマイズします。各カラーカテゴリーは、UI の 1 つ以上のコンポーネントの色を決定します。たとえば、[primary](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-colors/index.html#1242160296%2FProperties%2F2002900378) は、**支払う**ボタンと、**このカードを保存**のチェックボックスといった選択された項目の色を定義します。下の図で、各カラーカテゴリーに関連付けられた UI エレメントをご覧いただけます。 > ダークモードに対応するには、[appearance.colorsDark](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-appearance/index.html#945237406%2FProperties%2F2002900378) を設定します。[appearance.colorsDark](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-appearance/index.html#945237406%2FProperties%2F2002900378) を [appearance.colorsLight](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-appearance/index.html#2092498352%2FProperties%2F2002900378) と同じ値に設定することで、ダークモードを効果的に無効にすることができます ![](https://b.stripecdn.com/docs-statics-srv/assets/android-appearance-colors.413c76aaf01a54c25478cb8d7532c7e7.png) ## 形状 フォントとカラーをカスタマイズするだけでなく、[appearance.shapes](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-appearance/index.html#-2108514638%2FProperties%2F2002900378) を設定することで、Mobile Payment Element 全体で使用される[コーナー半径](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-shapes/index.html#-1129752289%2FProperties%2F2002900378)と[枠線の幅](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-shapes/index.html#495484314%2FProperties%2F2002900378)もカスタマイズできます。 ![](https://b.stripecdn.com/docs-statics-srv/assets/android-appearance-shapes.800169ea6a81e0bfdbccbb18bfdf7121.png) ## 特定の UI コンポーネント 上記のセクションでは、複数の UI コンポーネントにわたりモバイル Payment Element に広く影響を与えるカスタマイズオプションについて説明しています。また、1 次ボタン (たとえば、**支払う**ボタン) 専用のカスタマイズオプションも提供しています。カスタマイズオプションの詳細なリストについては、[Appearance.PrimaryButton](https://stripe.dev/stripe-android/paymentsheet/com.stripe.android.paymentsheet/-payment-sheet/-primary-button/index.html) をご覧ください。 一部の UI コンポーネントのカスタマイズオプションは、他の値よりも優先されます。たとえば、`appearance.primaryButton.shapes.cornerRadius` は、`appearance.shapes.cornerRadius` の値を上書きします。 > その他のカスタマイズオプションのアイデアがございましたら、[お知らせください](https://github.com/stripe/stripe-android/issues/new/choose)。 # React Native > This is a React Native for when platform is react-native. View the full page at https://docs.stripe.com/elements/appearance-api/mobile?platform=react-native. [モバイル支払い Element](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=mobile&platform=react-native) は視覚的なカスタマイズをサポートしているため、アプリのデザインに合わせてカスタマイズできます。レイアウトの一貫性は保たれますが、[initPaymentSheet()](https://stripe.dev/stripe-react-native/api-reference/index.html#initPaymentSheet) を呼び出すときに `appearance` パラメーターを含めることで、色やフォントなどを変更できます。 1. 最初に[フォント](https://docs.stripe.com/elements/appearance-api/mobile.md#fonts-react-native)をカスタマイズします。 1. アプリに合わせて[カラー](https://docs.stripe.com/elements/appearance-api/mobile.md#colors-react-native)をカスタマイズします。 1. 境界半径などの[形状](https://docs.stripe.com/elements/appearance-api/mobile.md#shapes-react-native)をカスタマイズします。 1. [特定のコンポーネント](https://docs.stripe.com/elements/appearance-api/mobile.md#specific-ui-components-react-native)を微調整します。 ![](https://b.stripecdn.com/docs-statics-srv/assets/ios-appearance-before-after-example.ad6a9aad238be9b198e9ebbc77ebe1d4.png) ```js // The following code creates the appearance shown in the screenshot aboveconst customAppearance = { font: { family: Platform.OS === 'android' ? 'avenirnextregular' : 'AvenirNext-Regular', }, shapes: { borderRadius: 12, borderWidth: 0.5, }, primaryButton: { shapes: { borderRadius: 20, }, }, colors: { primary: '#fcfdff', background: '#ffffff', componentBackground: '#f3f8fa', componentBorder: '#f3f8fa', componentDivider: '#000000', primaryText: '#000000', secondaryText: '#000000', componentText: '#000000', placeholderText: '#73757b', }, }; const { error } = await initPaymentSheet({ ...appearance: customAppearance, }); ``` ## フォント [FontConfig](https://stripe.dev/stripe-react-native/api-reference/modules/PaymentSheet.html#FontConfig) を `font` に渡し、`family` を設定して、フォントをカスタマイズします。iOS では、`family` の値には Font Book にある「PostScript 名」を指定する必要があります。Android では、`.ttf` ファイルまたは `.otf` ファイルを `android/app/src/main/assets/font/` から `android/app/src/main/res/font/` にコピーして、フォントファイルの名前 (小文字、英数字のみ) を使用します。Mobile Payment Element では、カスタムフォントのフォントファミリーが使用されますが、サイズと太さは自動的に決定されます。 テキストのサイズを拡大縮小するには、`scale` を設定します。フォントサイズは、この値で乗算されてから表示されます。これは、カスタムフォントがシステムフォントよりも若干大きいか小さい場合に役立ちます。 ```js ...const appearance: AppearanceParams = { font: { family: Platform.OS === 'android' ? 'avenirnextregular' : 'AvenirNext-Regular', scale: 1.15, }, }, ``` ## カラー モバイルの Payment Element で、[Appearance.Colors](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance.html#/s:6Stripe12PaymentSheetC10AppearanceV6ColorsV) で定義されているカラーカテゴリーを変更することにより、色をカスタマイズします。各カラーカテゴリーは、UI の 1 つ以上のコンポーネントの色を決定します。たとえば、[primary](https://stripe.dev/stripe-ios/stripe-paymentsheet/Classes/PaymentSheet/Appearance/Colors.html#/s:6Stripe12PaymentSheetC10AppearanceV6ColorsV7primarySo7UIColorCvp) は、**支払う**ボタンと、**このカードを保存**のチェックボックスといった選択された項目の色を定義します。下の図で、各カラーカテゴリーに関連付けられた UI エレメントをご覧いただけます。 ![](https://b.stripecdn.com/docs-statics-srv/assets/ios-appearance-colors.2063c1f71eaa17656639098f3f4d29d6.png) > ダークモードをサポートするには、[init(dynamicProvider:)](https://developer.apple.com/documentation/uikit/uicolor/3238041-init) を使用してカスタムの UIColors を初期化します。 ## 形状 フォントと色のほか、モバイル Payment Element 全体で使用されている[境界半径](https://stripe.dev/stripe-react-native/api-reference/modules/PaymentSheet.html#AppearanceParams)、[境界線の幅](https://stripe.dev/stripe-react-native/api-reference/modules/PaymentSheet.html#AppearanceParams)、[シャドウ](https://stripe.dev/stripe-react-native/api-reference/modules/PaymentSheet.html#ShadowConfig)もカスタマイズできます。 ![](https://b.stripecdn.com/docs-statics-srv/assets/react-native-appearance-shapes.a71c754a951ea02fff121f584953ba33.png) ## 特定の UI コンポーネント これまでのセクションでは、複数の UI コンポーネントにわたり Mobile Payment Element に広く影響を与えるカスタマイズオプションについて説明しました。これに加えて、プライマリーボタン (たとえば、**支払う**ボタン) 専用のカスタマイズオプションも提供しています。カスタマイズオプションの一覧については、[PrimaryButtonConfig](https://stripe.dev/stripe-react-native/api-reference/modules/PaymentSheet.html#PrimaryButtonConfig) をご覧ください。 一部の UI コンポーネントのカスタマイズオプションは、他の値よりも優先されます。たとえば、`primaryButton.shapes.borderRadius` は、`shapes.borderRadius` の値を上書きします。 > より多くのカスタマイズオプションの提供が必要と思われる場合は、[お知らせください](https://github.com/stripe/stripe-react-native/issues/new/choose)。