刚刚的【2019 WWDC 大会】苹果发布了 SwiftUI 开发语言,咋看上去,和Flutter的UI比较像,但个人感觉比Flutter的方式更好——虽然有些地方比较奇怪。有兴趣的开发人员可以试着按链接操作一下:
Flutter的写法:
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
var stack = new Stack(
alignment: const Alignment(0.6, 0.6),
children: [
new CircleAvatar(
backgroundImage: new AssetImage('images/pic.jpg'),
radius: 100.0,
),
new Container(
decoration: new BoxDecoration(
color: Colors.black45,
),
child: new Text(
'Mia B',
style: new TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
],
);
}
}
SwiftUI的写法:
struct ContentView: View {
var body: some View {
VStack {
VStack(alignment: .leading) {
Text("Turtle Rock")
.font(.title)
HStack(alignment: .top) {
Text("Joshua Tree National Park")
.font(.subheadline)
Spacer()
Text("California")
.font(.subheadline)
}
}
.padding()
}
}
}
我保留个人意见暂不评论,看大家怎么看。
网友评论