iOS 警告

2019-08-14 14:23 更新

利用一個(gè)特定的標(biāo)題和消息來啟動(dòng)一個(gè)警告對(duì)話框。

提供一個(gè)可選按鈕的列表。點(diǎn)擊任何按鈕觸發(fā)各自的按下回調(diào)動(dòng)作,并且忽略警告。在默認(rèn)情況下,只有一個(gè)按鈕是“OK”按鈕。列表中最后一個(gè)按鈕被視為“主”按鈕,它被用粗體顯示出來了。

    AlertIOS.alert(      'Foo Title',      'My Alert Msg',
      [
        {text: 'Foo', onPress: () => console.log('Foo Pressed!')},
        {text: 'Bar', onPress: () => console.log('Bar Pressed!')},
      ]
    )}

方法

static alert(title: string, message?: string, buttons?: Array<{ text: ?string; onPress: ?Function; }>)

例子

Edit on GitHub

    'use strict';    var React = require('react-native');    var {
      StyleSheet,
      View,
      Text,
      TouchableHighlight,
      AlertIOS,
    } = React;
    exports.framework = 'React';
    exports.title = 'AlertIOS';
    exports.description = 'iOS alerts and action sheets';
    exports.examples = [{      title: 'Alerts',
      render() {        return (
          <View>
            <TouchableHighlight style={styles.wrapper}
              onPress={() => AlertIOS.alert(                'Foo Title',                'My Alert Msg'
              )}>
              <View style={styles.button}>
                <Text>Alert with message and default button</Text>
              </View>
            </TouchableHighlight>
            <TouchableHighlight style={styles.wrapper}
              onPress={() => AlertIOS.alert(                null,                null,
                [
                  {text: 'Button', onPress: () => console.log('Button Pressed!')},
                ]
              )}>
              <View style={styles.button}>
                <Text>Alert with only one button</Text>
              </View>
            </TouchableHighlight>
            <TouchableHighlight style={styles.wrapper}
              onPress={() => AlertIOS.alert(                'Foo Title',                'My Alert Msg',
                [
                  {text: 'Foo', onPress: () => console.log('Foo Pressed!')},
                  {text: 'Bar', onPress: () => console.log('Bar Pressed!')},
                ]
              )}>
              <View style={styles.button}>
                <Text>Alert with two buttons</Text>
              </View>
            </TouchableHighlight>
            <TouchableHighlight style={styles.wrapper}
              onPress={() => AlertIOS.alert(                'Foo Title',                null,
                [
                  {text: 'Foo', onPress: () => console.log('Foo Pressed!')},
                  {text: 'Bar', onPress: () => console.log('Bar Pressed!')},
                  {text: 'Baz', onPress: () => console.log('Baz Pressed!')},
                ]
              )}>
              <View style={styles.button}>
                <Text>Alert with 3 buttons</Text>
              </View>
            </TouchableHighlight>
            <TouchableHighlight style={styles.wrapper}
              onPress={() => AlertIOS.alert(                'Foo Title',                'My Alert Msg',                '..............'.split('').map((dot, index) => ({                  text: 'Button ' + index,                  onPress: () => console.log('Pressed ' + index)
                }))
              )}>
              <View style={styles.button}>
                <Text>Alert with too many buttons</Text>
              </View>
            </TouchableHighlight>
          </View>
        );
      },
    }];    var styles = StyleSheet.create({      wrapper: {        borderRadius: 5,        marginBottom: 5,
      },      button: {        backgroundColor: '#eeeeee',        padding: 10,
      },
    });


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)