gpt4 book ai didi

ios - 如何在 Swift 4 中的 UIPickerView 中的文本旁边添加图像或图标?

转载 作者:行者123 更新时间:2023-11-30 12:01:41 25 4
gpt4 key购买 nike

我已经做到了这一点,它毫无问题地回复了我的文本:

    class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

@IBOutlet weak var foodLabel: UILabel!
@IBOutlet weak var foodSlider: UIPickerView!

var picker = UIPickerView()

let foodsScroll = ["pizza \npepperoni" ,"chicken \nnuggets ","meat \nballs","hamburger \nbloody","omelette \ngrilled","ice cream \nberry"]

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 80.00
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

let cgRect = CGRect(x: 0.00, y: 0.00, width: 400, height: 200)
let label = UILabel(frame: cgRect)
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.text = foodsScroll[row]
label.sizeToFit()
return label
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return foodsScroll[row]
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

return foodsScroll.count
}


func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
foodLabel.text = foodsScroll[row]
}

override func viewDidLoad() {

}

}

说到我需要在每种食物名称的一侧添加一个图标的部分。我不太清楚它是如何完成的,但我知道你可以使用两种简单的方法:

  1. 使用额外的 UIView 和
  2. 使用 UIImage。

也欢迎任何替代方法。

最佳答案

你就是问题,你就是答案是的!这里有两种简单的方法来添加您的想法 1)使用额外的 UIView 和 2)使用UIImage。 3)创建一张卡片最后,这是一张卡片。但它与 UIView 相同

https://github.com/aclissold/CardView

关于ios - 如何在 Swift 4 中的 UIPickerView 中的文本旁边添加图像或图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47136952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com