我知道这个问题看似重复,但请在downvote之前阅读!
我有ReachabilityViewController
,其中有一个名为pickerView
的UIView,如下图所示
我想要的结果是:
但我得到了这个:
这是我的viewController类:
import UIKit
class ReachabilityViewController: UIViewController {
//MARK: pickerView outlets and actions
@IBOutlet weak var pickerView: UIView!
@IBOutlet weak var saveButton: UIButton!
@IBOutlet weak var cancelButton: UIButton!
@IBOutlet weak var startEndLabel: UILabel!
@IBOutlet weak var timePicker: UIDatePicker!
override func viewDidLoad() {
super.viewDidLoad()
pickerView.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
}
// MARK: - Table view data source
extension ReachabilityViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.view.addSubview(pickerView)
pickerView.alpha = 0.0
UIView.animate(withDuration: 0.3) {
self.pickerView.alpha = 1.0
}
}
}
如何获得我想要的效果?
我已将pickerView
backgroundColor设置为清除。
答案 0 :(得分:3)
这就是我所做的
class ViewController: UIViewController,UIPickerViewDataSource, UIPickerViewDelegate {
var pickerDataSource = ["White", "Red", "Green", "Blue"];
@IBOutlet var pickerView: UIPickerView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.regular)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.pickerView.delegate = self
self.pickerView.dataSource = self
self.view.addSubview(blurEffectView)
self.view.bringSubview(toFront: self.pickerView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count;
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickerDataSource[row]
}