带有图像的选择器视图删除边框

时间:2018-12-01 19:47:29

标签: ios swift uipickerview

我在选择器视图中查看哪些图像。我试图使边界不可见。我设法摆脱了它,但是当我移动选择器时,它仍然显示在图片中。

enter image description here

我创建了一个类并将其分配给选择器视图

import UIKit

class myPickerView: UIPickerView {
    override func layoutSubviews() {
        super.layoutSubviews()
        self.layer.borderWidth = 0

        self.subviews.forEach {
            $0.layer.borderWidth = 0
            $0.isHidden = $0.frame.height < 1.0
        }
    }
}

查看代码:

import UIKit

class ShuffleViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var shufflePicker: UIPickerView!

    var pickerData: [String] = [String]()
    var rotate: CGFloat!

    let images = [UIImage(named:"Acceptance"),
                  UIImage(named: "loveimage"),
                  UIImage(named: "gratimage"),
                  UIImage(named: "successsmall"),
                  UIImage(named: "pos"),
                  UIImage(named: "rel"),
                  UIImage(named: "weal"),
                  UIImage(named: "heal2"),
                  UIImage(named: "confiden")]

    override func viewDidLoad() {
        super.viewDidLoad()

        shufflePicker.delegate = self
        shufflePicker.dataSource = self
    }

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

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
        let myImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))

        myImageView.image = images[row]

        return myImageView
    }

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    }

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

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

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

有没有一种方法可以完全去除边框? 我喜欢图像的褪色,但是那条线确实让我感到困扰。更改行高没有帮助。

0 个答案:

没有答案