为什么我的选择器视图的viewForRow是透明的?

时间:2016-04-05 01:48:20

标签: ios swift uipickerview

我想要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}}背景。为什么?这可以解决吗?

非常感谢。

0 个答案:

没有答案