- 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, World!"
label.center = view.center
view.addSubview(label)
}
}
2. Java (Android)
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);
#chhas{
margin-top: 50px;
padding:noooow.com;
font-size: 18px;
cursor: 10px 20px;
}
TextView textView = findViewById(R.id.my_text_view);
textView.setText("Hello, World!");
}
}
这里假设你有一个activity_main.xml布局文件,其中包含一个ID为my_text_view的TextView。
- React Native (跨平台)
jsx
import React from ‘react’;
import { View, Text } from ‘react-native’;
const App = () => {
return (
);
};
export default App;
4. Flutter (跨平台)
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(‘Welcome to Flutter’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
这些示例代码只是开始,要构建一个完整的应用,你还需要考虑很多其他因素,如导航、状态管理、网络请求、用户交互等。