gpt4 book ai didi

ios - React Native 仅适用于 UI 组件

转载 作者:行者123 更新时间:2023-12-01 15:28:55 25 4
gpt4 key购买 nike

我有一个用 Swift 编写的非常简单的 ViewController,它的 UI 内置在 Storyboard 中。它只是在有人按下按钮时更改标签的文本。

class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!

@IBAction func changeText() {
switch label.text! {
case "Old Text":
label.text = "New Text"
case "New Text":
label.text = "Old Text"
default:
break
}
}
}

我想在我的项目中使用 React Native,但只处理 UI 组件,而不是应用程序逻辑本身。我该怎么办?我已经布置了按钮和带有反应的文本。
var Button = require('react-native-button');

class TestProject extends Component {
render() {
return (
<View style={styles.container}>
<Button style={styles.button}>Change Text</Button>
<Text style={styles.text}>
Text to be changed
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
text: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
button: {
borderWidth: 1,
borderColor: 'blue'
},
});

更广泛地说,如果我想要的是可能的,使用这种方法来实现更强大和更健壮的应用程序是否仍然可行?

最佳答案

关于ios - React Native 仅适用于 UI 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37145374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com