- Swift (iOS App)aladingroup.cn
Swift 是 Apple 官方推荐的 iOS 和 macOS 应用开发语言。
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.center = view.center
view.addSubview(label)
}
}
2. Java (Android App)
Java 是 Android 官方支持的开发语言。但现代 Android 开发更倾向于使用 Kotlin。
java
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textView);
textView.setText("Hello, World!");
}
}
3. Flutter (跨平台App)
Flutter 使用 Dart 语言开发跨平台的移动应用。
main.dart
dart
import ‘package:flutter/material.dart’;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(‘Hello World’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
4. React Native (跨平台App)
React Native 使用 JavaScript (配合 JSX) 和 React 构建原生应用的框架。
App.js
jsx
import React from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;
const App = () => {
return (
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
},
});
export default App;
以上代码仅提供了每个平台的基本结构和“Hello, World!”的输出。要构建一个完整的App,你需要进一步添加功能、界面设计、交互等。由于不同的编程语言有各自的特性和应用领域,直接生成一个完整的App代码对于所有平台(如iOS、Android、Web等)和所有编程语言来说是不现实的。但我可以为你提供几种常见编程语言中用于创建App的示例代码片段或框架。
- Swift (iOS App)
Swift 是 Apple 官方推荐的 iOS 和 macOS 应用开发语言。
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.center = view.center
view.addSubview(label)
}
}
2. Java (Android App)
Java 是 Android 官方支持的开发语言。但现代 Android 开发更倾向于使用 Kotlin。
java
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textView);
textView.setText("Hello, World!");
}
}
3. Flutter (跨平台App)
Flutter 使用 Dart 语言开发跨平台的移动应用。
main.dart
dart
import ‘package:flutter/material.dart’;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text(‘Hello World’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
4. React Native (跨平台App)
React Native 使用 JavaScript (配合 JSX) 和 React 构建原生应用的框架。
App.js
jsx
import React from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;
const App = () => {
return (
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
},
});
export default App;
以上代码仅提供了每个平台的基本结构和“Hello, World!”的输出。要构建一个完整的App,你需要进一步添加功能、界面设计、交互等。