我可以更改UIPickerView分隔符高度吗?

问题描述 投票:0回答:1

我已经实现了一个选择器视图,但现在我想更改选择器视图分隔线高度。我想要更厚的隔板衬垫而不是这个默认线。那么这有可能改变分离器的高度???

enter image description here

我想要线如下图所示。

enter image description here

ios iphone swift uipickerview picker
1个回答
4
投票

在pickerView的委托方法中更改线视图的高度:

public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    for view in pickerView.subviews {
        if view.frame.size.height < 1 {
            var frame = view.frame
            frame.size.height = 2
            view.frame = frame
            view.backgroundColor = UIColor.black
        }
    }

    let label = UILabel()
    label.text = "Test Text" //remember to change it to the real data
    label.textAlignment = NSTextAlignment.center
    return label
}

记得设置PickerView的委托:

self.pickerView.delegate = self //or do this in XIB or Storyboard.

效果: enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.