我想要viewForRow
pickerView
UIPickerView
个实例的不透明class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
weak var pickerView: UIPickerView! {
didSet {
pickerView.dataSource = self
pickerView.delegate = self
pickerView.backgroundColor = .clearColor()
pickerView.showsSelectionIndicator = true
pickerView.frame = CGRect(x: 50, y: 200, width: 100, height: 100)
view.addSubview(pickerView)
}
}
override func viewDidLoad() {
super.viewDidLoad()
pickerView = UIPickerView()
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 2
}
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
let rowSize = pickerView.rowSizeForComponent(component)
let aView = UIView(frame: CGRect(x: 0, y: 0, width: rowSize.width, height: rowSize.height))
aView.opaque = true
aView.backgroundColor = .blackColor()
return aView
}
}
。我现在正在做的是一个半透明的视图!
这就是我所拥有的:
ViewController
您可以在view
后面看到aView
的{{1}}背景。为什么?这可以解决吗?
非常感谢。