前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SwiftUI之List Group NavigationView ForEach

SwiftUI之List Group NavigationView ForEach

作者头像
大话swift
发布2019-07-03 17:00:27
1.3K0
发布2019-07-03 17:00:27
举报
文章被收录于专栏:大话swift大话swift

List

public struct List<Selection, Content> where Selection : SelectionManager, Content : View {

/// Creates an instance.

///

/// - Parameter selection: A selection manager that identifies the selected row(s).

///

/// - See Also: `View.selectionValue` which gives an identifier to the rows.

///

/// - Note: On iOS and tvOS, you must explicitly put the `List` into Edit

/// Mode for the selection to apply.

@available(watchOS, unavailable)

public init(selection: Binding<Selection>?, content: () -> Content)

/// The type of view representing the body of this view.

///

/// When you create a custom view, Swift infers this type from your

/// implementation of the required `body` property.

public typealias Body = Never

}

实例:

List(landmarkData) { landmark in

NavigationButton(destination: LandmarkDetail(landmark: landmark)) {

LandmarkRow(landmark: landmark)

}

}

Nav

public struct NavigationView<Root> where Root : View {

public init(root: () -> Root)

public var body: _View { get }

/// The type of view representing the body of this view.

///

/// When you create a custom view, Swift infers this type from your

/// implementation of the required `body` property.

public typealias Body

}

实例

NavigationView {

Text("我是内容").navigationBarTitle(Text("我是标题"), displayMode: .large)

}

ForEach

public struct ForEach<Data, Content> where Data : RandomAccessCollection, Content : View, Data.Element : Identifiable {

/// The collection of underlying identified data.

public var data: Data

/// A function that can be used to generate content on demand given

/// underlying data.

public var content: (Data.Element.IdentifiedValue) -> Content

/// Creates an instance that uniquely identifies views across updates based

/// on the identity of the underlying data element.

///

/// It's important that the id of a data element does not change

/// unless the data element is considered to have been replaced with a new

/// data element with a new identity. If the id of a data element

/// changes, then the content view generated from that data element will

/// lose any current state and animations.

public init(_ data: Data, content: @escaping (Data.Element.IdentifiedValue) -> Content)

/// The type of view representing the body of this view.

///

/// When you create a custom view, Swift infers this type from your

/// implementation of the required `body` property.

public typealias Body = Never

}

实例:多屏时时预览

#if DEBUG

struct LandmarkList_Previews: PreviewProvider {

static var previews: some View {

ForEach(["iPhone SE", "iPhone XS Max"].identified(by: \.self)) { deviceName in

LandmarkList()

.previewDevice(PreviewDevice(rawValue: deviceName))

.previewDisplayName(deviceName)

}

}

}

#endif

Group

public struct Group<Content> where Content : View {

public init(content: () -> Content)

/// The type of view representing the body of this view.

///

/// When you create a custom view, Swift infers this type from your

/// implementation of the required `body` property.

public typealias Body = Never

}

实例:

#if DEBUG

struct LandmarkRow_Previews: PreviewProvider {

static var previews: some View {

Group {

LandmarkRow(landmark: landmarkData[0])

LandmarkRow(landmark: landmarkData[1])

}

.previewLayout(.fixed(width: 300, height: 70))

}

}

#endif

实例数据根据官方实例修改说明

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大话swift 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档