首页 > 解决方案 > 如何快速在 Segmentio 中添加文本和图像数组

问题描述

我正在使用segmentio pod 来分割图像和文本,我在项目中添加了 pod 并在情节提要中添加了视图,并分配了 Segmentio 类名并导入了 Segmentio。

这里如何在segmentio中添加文本和图像数组

我试过如下:

 import UIKit
 import Segmentio
 class EventsDashboardViewController: UIViewController {

@IBOutlet weak var segmentioView: Segmentio!

//var swipeMenuArray: NSMutableArray = []
var content = [SegmentioItem]()

override func viewDidLoad() {
        super.viewDidLoad()

 segmentioView.setup(
    content: [SegmentioItem],
    style: SegmentioStyle,
    options: SegmentioOptions?
)

    
    let tornadoItem = SegmentioItem(
        (title: "Alert",
        image: UIImage(named: "img1")),
        (title: "Message",
        image: UIImage(named: "img2")),
        (title: "Stared",
        image: UIImage(named: "img3"))
    )
    content.append(tornadoItem)

 }

 }

错误

一行中的连续声明必须用';'分隔

调用中缺少参数标签“title:image:selectedImage:”

一行中的连续声明必须用';'分隔

标签: iosswiftsegmentsegment-io

解决方案


这不是有效的 Swift。说的部分

segmentioView.setup(
    content: [SegmentioItem],
    style: SegmentioStyle,
    options: SegmentioOptions?
)

无效。它看起来像是函数调用和函数定义的组合。

我可以看到 Segmentio 的文档不是很清楚,并且还包含此无效代码。

正确的用法可能是这样的:

override func viewDidLoad() {
  super.viewDidLoad()

  content.append(SegmentioItem(title: "Alert", image: UIImage(named: "img1"))
  content.append(SegmentioItem(title: "Message", image: UIImage(named: "img2"))
  content.append(SegmentioItem(title: "Stared", image: UIImage(named: "img3"))

  segmentioView.setup(
    content: content,
    style: .imageBeforeLabel,
    options: nil
  )
}

我不知道 Segmentio,所以这可能不是 100% 正确的。


推荐阅读