使用雨燕類和枚舉我已經包含了一組迅速類及其迅速的依賴關係到我的Objective-C的項目。我已經爲其他swift庫完成了這個工作,所以Obj-C生成的接口頭文件已經存在。從Objective-C的
這是我想使用的類:
@objc public class StatusBarNotificationBanner: BaseNotificationBanner
{
override init(style: BannerStyle) {
super.init(style: style)
bannerHeight = 20.0
titleLabel = MarqueeLabel()
titleLabel?.animationDelay = 2
titleLabel?.type = .leftRight
titleLabel!.font = UIFont.systemFont(ofSize: 12.5, weight: UIFontWeightBold)
titleLabel!.textAlignment = .center
titleLabel!.textColor = .white
addSubview(titleLabel!)
titleLabel!.snp.makeConstraints { (make) in
make.top.equalToSuperview()
make.left.equalToSuperview().offset(5)
make.right.equalToSuperview().offset(-5)
make.bottom.equalToSuperview()
}
updateMarqueeLabelsDurations()
}
public convenience init(title: String, style: BannerStyle = .info) {
self.init(style: style)
titleLabel!.text = title
}
public convenience init(attributedTitle: NSAttributedString, style: BannerStyle = .info) {
self.init(style: style)
titleLabel!.attributedText = attributedTitle
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
這是一個如何使用SWIFT類:
let banner = StatusBarNotificationBanner(title: title, style: .success)
banner.show()
如何在對象 - 我想實例StatusBarNotificationBanner並調用其show()方法?
而且,我如何通過枚舉參數風格?
這是枚舉:
public enum BannerStyle {
case danger
case info
case none
case success
case warning
}
我猜枚舉需要採取以下形式:
@objc public enum BannerStyle: Int {
case danger
case info
case none
case success
case warning
}
但我仍然不知道如何把它作爲在一個的OBJ PARAM -C和我不明白爲什麼必須指定Int?是不是隱式的Int?
感謝您回答有關枚舉問題的部分,但我的更大的問題是如何實例化此類並從Objective-C調用show方法(將枚舉值作爲params之一)。 – bhartsb
通過查看自動生成的Objective-C橋接頭,您可以輕鬆找到這一切。最簡單的方法是命令單擊您的Objective-C文件導入橋接頭的名稱。 – matt
同樣的答案。查看橋接頭並查看該類的Objective-C初始化程序。 – matt