我有一个按钮,可以在全屏上显示一个弹出窗口。主视图有6个自定义视图,每个自定义视图都有5个带有灰色或蓝色的色调按钮,具体取决于某些参数。但是当弹出窗口出现时,所有自定义视图内的按钮都变成灰色。弹出窗口消失后,自定义视图恢复其色调颜色。我想避免在呈现弹出窗口时按钮色调颜色发生变化。 自定义视图是UITableviewCell中的一个视图,该自定义视图定义如下。
class ratingDoors: UIView {
var rating: Int = 0{
didSet{
makeRating()
}
}
@IBOutlet var contentView: UIView!
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var button3: UIButton!
@IBOutlet weak var button4: UIButton!
@IBOutlet weak var button5: UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
//fatalError("init(coder:) has not been implemented")
}
private func commonInit() {
//TODO: Do some stuff
// 1. Load the nib
Bundle.main.loadNibNamed("ratingDoors", owner: self, options: nil)
// 2. Add the 'contentView' to self
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = [.flexibleHeight,.flexibleWidth]
}
@IBAction func setRating(sender: UIButton){
rating = sender.tag
//makeRating()
}
func makeRating() {
button1.configureRatingButton(i: rating)
button2.configureRatingButton(i: rating)
button3.configureRatingButton(i: rating)
button4.configureRatingButton(i: rating)
button5.configureRatingButton(i: rating)
}
}
extension UIButton{
func configureRatingButton(i: Int){
if self.tag <= i {
self.tintColor = UIColor(red: 90/255, green: 212/255, blue: 227/255, alpha: 1.0)
}else{
self.tintColor = UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1)
}
}
}
在tableview中,我为单元格设置了这个设置
let cell = tableView.dequeueReusableCell(withIdentifier: "ratingCell") as! ratingTableViewCell
cell.ratingLabel.text = "Ordenado"
if let ordered = requestManager.instance.user.ordered{
cell.ratingView.rating = ordered
}
return cell
对于所有6行,视图都是相同的。这里是`prepare(for:)`方法。
let popoverVC = segue.destination as! popoverViewController
popoverVC.delegate = self
popoverVC.modalPresentationStyle = UIModalPresentationStyle.popover
popoverVC.popoverPresentationController!.delegate = self