在这里插入图片描述

  1. Swift (iOS)jzsafe.com
    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, iOS App!"  
    label.frame = CGRect(x: 50, y: 50, width: 200, height: 50)  
    self.view.addSubview(label)  
}  

}
2. Java (Android)
java
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    TextView textView = new TextView(this);  
    textView.setTextSize(20);  
    textView.setText("Hello, Android App!");  
    setContentView(textView);  
}  

}
3. Flutter (跨平台)
Dart 代码 (Flutter 使用 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(‘Flutter App’),
),
body: Center(
child: Text(‘Hello, Flutter App!’),
),
),
);
}
}
4. React Native (跨平台)
JavaScript 代码 (React Native 使用 JavaScript 和 JSX)

jsx
import React from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;

export default function App() {
return (

Hello, React Native App!

);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
},
});
5. Python (Kivy - 跨平台Python GUI框架)
python
from kivy.app import App
from kivy.uix.label import Label

class TestApp(App):
def build(self):
return Label(text=‘Hello, Kivy App!’)

if name == ‘main’:
TestApp().run()
请注意,这些示例只是展示了如何创建一个简单的界面,并显示一条消息。要开发一个完整的app,你还需要考虑许多其他因素,如用户交互、数据处理、网络请求等。由于生成一个完整的app代码涉及多个层面(如UI设计、后端逻辑、数据存储等),并且不同的平台(如iOS、Android、Web等)有不同的开发语言和工具,所以在这里我将为你提供几个简单示例,展示如何使用不同的编程语言来编写一些基础的app逻辑。

  1. Swift (iOS)
    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, iOS App!"  
    label.frame = CGRect(x: 50, y: 50, width: 200, height: 50)  
    self.view.addSubview(label)  
}  

}
2. Java (Android)
java
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    TextView textView = new TextView(this);  
    textView.setTextSize(20);  
    textView.setText("Hello, Android App!");  
    setContentView(textView);  
}  

}
3. Flutter (跨平台)
Dart 代码 (Flutter 使用 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(‘Flutter App’),
),
body: Center(
child: Text(‘Hello, Flutter App!’),
),
),
);
}
}
4. React Native (跨平台)
JavaScript 代码 (React Native 使用 JavaScript 和 JSX)

jsx
import React from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;

export default function App() {
return (

Hello, React Native App!

);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
},
});
5. Python (Kivy - 跨平台Python GUI框架)
python
from kivy.app import App
from kivy.uix.label import Label

class TestApp(App):
def build(self):
return Label(text=‘Hello, Kivy App!’)

if name == ‘main’:
TestApp().run()
请注意,这些示例只是展示了如何创建一个简单的界面,并显示一条消息。要开发一个完整的app,你还需要考虑许多其他因素,如用户交互、数据处理、网络请求等。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐