美文网首页Flutter
SwiftUI,是FlutterUI该有的样子吗?

SwiftUI,是FlutterUI该有的样子吗?

作者: IT晴天 | 来源:发表于2019-06-04 18:16 被阅读46次

    刚刚的【2019 WWDC 大会】苹果发布了 SwiftUI 开发语言,咋看上去,和Flutter的UI比较像,但个人感觉比Flutter的方式更好——虽然有些地方比较奇怪。有兴趣的开发人员可以试着按链接操作一下:

    https://developer.apple.com/tutorials/swiftui/

    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()
            }
        }
    }
    

    我保留个人意见暂不评论,看大家怎么看。

    相关文章

      网友评论

        本文标题:SwiftUI,是FlutterUI该有的样子吗?

        本文链接:https://www.haomeiwen.com/subject/ccerxctx.html