【发布时间】:2020-10-28 10:53:36
【问题描述】:
我正在使用this cocoapod 作为一个小弹出视图来重置所有存储的 UserDefaults。因此,我希望弹出窗口的“是”和“否”按钮水平对齐(默认为垂直)。这是我的代码:
resetBtn.touchUpInside{ [self] in
let dialogAppearance = PopupDialogDefaultView.appearance()
let buttonAppearance = DefaultButton.appearance()
let title = "Do you really want to reset this game?"
let popup = PopupDialog(title: title)
let yesBtn = DefaultButton(title: "Yes", height: 60) {
self.click()
defaults.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
defaults.synchronize()
}
let noBtn = DefaultButton(title: "No", height: 60) {
self.click()
}
popup.addButton(yesBtn)
popup.addButton(noBtn)
dialogAppearance.messageFont = UIFont(name: "Nunito-Black", size: 18)!
dialogAppearance.messageTextAlignment = .natural
dialogAppearance.titleFont = UIFont(name: "Nunito-Black", size: 22)!
buttonAppearance.titleFont = UIFont(name: "Nunito-Black", size: 22)!
let vc = popup.viewController as! PopupDialogDefaultViewController //!!!
vc.buttonAlignment = .horizontal /// Cannot infer contextual base in reference to member 'horizontal', Value of type 'PopupDialogDefaultViewController' has no member 'buttonAlignment'
self.present(popup, animated: true, completion: nil)
}
如您所见right here,Creator 将按钮水平放置:
let vc = popup.viewController as! PopupDialogDefaultViewController
vc.buttonAlignment = .horizontal
但是当我这样做时,编译器会说“无法推断成员'水平'的上下文基础”,“'PopupDialogDefaultViewController' 类型的值没有成员'buttonAlignment'”.. . 在我的代码中标记。
我该怎么办?
【问题讨论】:
-
PopupDialogDefaultViewController是什么?它是否有一个名为buttonAlignment的属性? -
@Larme 它是 Cocoapod 的最终公共类,我没有名为 buttonAlignment 的属性。但是 PopupDialog 有
-
但是正如你在最后一个超链接中看到的那样,pod 描述就像我一样
-
我明白了。我猜:
vc.view.buttonAlignment可能有用,可能需要 (vc.view as!PopDialog).buttonliignment` -
然后它说“从 'UIView 投射?'到不相关的类型 'PopupDialog' 总是失败”。由于视图不是弹出视图。