- Swift (用于iOS App开发)ftinc.cn
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.frame = CGRect(x: 50, y: 100, width: 200, height: 50)
self.view.addSubview(label)
}
}
2. Java (用于Android App开发)
在Android中,你通常会使用XML来定义布局,但这里是一个简单的Java示例:
java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText(“Hello, World!”);
setContentView(textView);
}
}
3. Python (使用Kivy库)
Kivy是一个用于开发多触摸应用的Python库:
python
from kivy.app import App
from kivy.uix.label import Label
class TestApp(App):
def build(self):
return Label(text=‘Hello, World!’)
if name == ‘main’:
TestApp().run()
4. JavaScript (使用React Native)
React Native允许你使用JavaScript和React构建原生应用:
jsx
import React from ‘react’;
import { View, Text } from ‘react-native’;
const App = () => {
return (
);
};
export default App;
5. Flutter (Dart语言)
Flutter是一个用于构建跨平台应用的SDK,使用Dart语言:
dart
import ‘package:flutter/material.dart’;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: ‘Flutter Demo’,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text(‘Flutter Demo Home Page’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
这些示例只是起点,真实的App开发会涉及更多的功能、设计和优化。由于直接为多种电脑语言生成一个完整的App代码超出了简单回答的范围,但我可以为你提供几种常见编程语言中创建简单App的框架或示例代码。请注意,这些示例将非常基础,并且不会涵盖App的所有功能或设计。
- Swift (用于iOS App开发)
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.frame = CGRect(x: 50, y: 100, width: 200, height: 50)
self.view.addSubview(label)
}
}
2. Java (用于Android App开发)
在Android中,你通常会使用XML来定义布局,但这里是一个简单的Java示例:
java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setText(“Hello, World!”);
setContentView(textView);
}
}
3. Python (使用Kivy库)
Kivy是一个用于开发多触摸应用的Python库:
python
from kivy.app import App
from kivy.uix.label import Label
class TestApp(App):
def build(self):
return Label(text=‘Hello, World!’)
if name == ‘main’:
TestApp().run()
4. JavaScript (使用React Native)
React Native允许你使用JavaScript和React构建原生应用:
jsx
import React from ‘react’;
import { View, Text } from ‘react-native’;
const App = () => {
return (
);
};
export default App;
5. Flutter (Dart语言)
Flutter是一个用于构建跨平台应用的SDK,使用Dart语言:
dart
import ‘package:flutter/material.dart’;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: ‘Flutter Demo’,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text(‘Flutter Demo Home Page’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
这些示例只是起点,真实的App开发会涉及更多的功能、设计和优化。