欢迎来到 UsabillaForm —— 一套旨在在其现有的 Swift 项目中显示反馈表单的类。
安装
pod 'UsabillaForm'
例子
一个表单必须提供 UsabillaForm 对象才能初始化。
let form = UsabillaForm(formID: "yourFormId", type: .FeedBack)
let usabilla = Usabilla(form: form)
usabilla.delegate = self
usabilla.configureFeedBackForm { [weak self] result in
switch result {
case .success(let form):
self?.present(form, animated: true, completion: nil)
case .failure(let error):
print(error.localizedDescription)
}
}
或评分视图
let form = UsabillaForm(formID: "yourFormId", type: .Rating)
let usabilla = Usabilla(form: form)
usabilla.delegate = self
usabilla.configureFeedBackForm { [weak self] result in
switch result {
case .success(let form):
self?.present(form, animated: true, completion: nil)
case .failure(let error):
print(error.localizedDescription)
}
}
您可以设置自定义属性,例如表单背景颜色、表单标题颜色和表单标题字体。
form.customProperties?.formBackgroundColor = .white
form.customProperties?.formTitleFont = UIFont.systemFont(ofSize: 14, weight: .light)
form.customProperties?.formTitleTextColor = .black
form.customProperties?.feedBackQuestionTitle = "Your Feedback ?"
在您的视图控制器中提供 UsabillaFormDelegate 的舒适度。
extension YourViewController: UsabillaFormDelegate {
func didFormSubmit(_ form: UIViewController, _ typedText: String) {
// form.dismiss(animated: true, completion: nil)
}
func didRatingSubmit(_ form: UIViewController, _ rating: Int) {
// form.dismiss(animated: true, completion: nil)
}
}
调查
let surveyQuestions = ["Question 1",
"Question 2",
"Question 3"]
let survey = UsabillaForm.Survey(surveyQuestions: surveyQuestions)
let form = UsabillaForm(formID: "yourFormId",
type: .Survey,
survey: survey)
usabilla = Usabilla(form: form)
usabilla.delegate = self
usabilla.configureSurvey { [weak self] result in
switch result {
case .success(let form):
self?.present(form, animated: true, completion: nil)
case .failure(let error):
print(error.localizedDescription)
}
}
}
调查委托将返回 [String: Int],包含调查问题和它们的评级。
func didSurveySubmitted(_ form: UIViewController, _ surveyResult: [String : Int]) {
form.dismiss(animated: true, completion: nil)
}