微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

修改行背景颜色列表 SwiftUI

如何解决修改行背景颜色列表 SwiftUI

我正在尝试更改列表中的行颜色。

# frame for the two buttons
top_inner_frame = tk.Frame(top_frame)
top_inner_frame.grid(row=1,column=0,columnspan=width)

button_1 = tk.Button(top_inner_frame,text='Move to Center Position')
button_1.pack(size="left",pady=pady_5)

button_2 = tk.Button(top_inner_frame,text='Move to Last Position')
button_2.pack(size="left",pady=pady_5)

输出:-

Screenshot

我想实现:-

Screenshot

有人可以向我解释如何更改整行颜色。我已经尝试通过上面的方法实现,但还没有结果。

任何帮助将不胜感激。

提前致谢。

解决方法

使用listRowBackground

var body: some View {
    VStack{
        List {
            ForEach(0...15,id: \.self,content: row(for:)).background(Color.red).listRowBackground(Color.red)
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。