Swift (iOS开发):wandarealmwuhan.cn
swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UIViewController()
window?.rootViewController?.view.backgroundColor = UIColor.white
window?.makeKeyAndVisible()
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
label.center = window!.center
label.textAlignment = .center
label.text = "Hello, World!"
window?.rootViewController?.view.addSubview(label)
return true
}
}
Kotlin (Android开发):
kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val textView = TextView(this)
textView.text = “Hello, World!”
textView.textSize = 20f
setContentView(textView)
}
}
Flutter (跨平台开发):
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!’),
),
),
);
}
}
React Native (跨平台开发):
jsx
import React from ‘react’;
import { AppRegistry, Text, View } from ‘react-native’;
const App = () => (
<View style={{ flex: 1, justifyContent: ‘center’, alignItems: ‘center’ }}>
);
AppRegistry.registerComponent(‘HelloWorldApp’, () => App);
这些示例只是起点,真实的APP开发会涉及更多的功能和复杂性。根据你的需求和目标平台,你可能需要深入学习相关的框架和工具。创建一个完整的APP需要涉及多个文件和复杂的架构,而且不同平台(如iOS、Android、Web等)有不同的开发要求和工具。但我可以为你提供一个简单的示例,用几种不同的编程语言来展示一个基本的“Hello, World!”程序,这可以作为APP的一部分。
Swift (iOS开发):
swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UIViewController()
window?.rootViewController?.view.backgroundColor = UIColor.white
window?.makeKeyAndVisible()
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
label.center = window!.center
label.textAlignment = .center
label.text = "Hello, World!"
window?.rootViewController?.view.addSubview(label)
return true
}
}
Kotlin (Android开发):
kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val textView = TextView(this)
textView.text = “Hello, World!”
textView.textSize = 20f
setContentView(textView)
}
}
Flutter (跨平台开发):
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!’),
),
),
);
}
}
React Native (跨平台开发):
jsx
import React from ‘react’;
import { AppRegistry, Text, View } from ‘react-native’;
const App = () => (
<View style={{ flex: 1, justifyContent: ‘center’, alignItems: ‘center’ }}>
);
AppRegistry.registerComponent(‘HelloWorldApp’, () => App);
这些示例只是起点,真实的APP开发会涉及更多的功能和复杂性。根据你的需求和目标平台,你可能需要深入学习相关的框架和工具。