Commit f2d7ce99 authored by Steven杜宇's avatar Steven杜宇

// 双项选择题

parent b3264fb0
...@@ -20,10 +20,12 @@ class YHDoubleChoiceQuestionCell: UITableViewCell { ...@@ -20,10 +20,12 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
let confirmTag = 9527 let confirmTag = 9527
let negativeTag = 9528 let negativeTag = 9528
var question:String? { var responseBlock:((Bool)->Void)?
didSet {
var title:String? {
didSet {
if let question = question { if let question = title {
let str = "*"+question let str = "*"+question
let attributes: [NSAttributedString.Key: Any] = [ let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.PFSCR(ofSize: 14), .font: UIFont.PFSCR(ofSize: 14),
...@@ -32,15 +34,18 @@ class YHDoubleChoiceQuestionCell: UITableViewCell { ...@@ -32,15 +34,18 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
let questionAttrStr = NSMutableAttributedString(string: str, attributes: attributes) let questionAttrStr = NSMutableAttributedString(string: str, attributes: attributes)
let starRange = NSRange(location: 0, length: 1) let starRange = NSRange(location: 0, length: 1)
questionAttrStr.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor(hex:0xFF3A3A), range: starRange) questionAttrStr.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor(hex:0xFF3A3A), range: starRange)
questionLabel.attributedText = questionAttrStr titleLabel.attributedText = questionAttrStr
} }
} }
} }
var selectBlock:((Bool) ->Void)? var response:Bool = false {
didSet {
showResponse(response)
}
}
lazy var questionLabel: UILabel = { lazy var titleLabel: UILabel = {
let label = UILabel() let label = UILabel()
label.numberOfLines = 0 label.numberOfLines = 0
label.textColor = UIColor(hexString:"#333333") label.textColor = UIColor(hexString:"#333333")
...@@ -84,14 +89,14 @@ class YHDoubleChoiceQuestionCell: UITableViewCell { ...@@ -84,14 +89,14 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
self.selectionStyle = .none self.selectionStyle = .none
question = " 1、是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪? " title = " 1、是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪? "
contentView.addSubview(questionLabel) contentView.addSubview(titleLabel)
contentView.addSubview(negativeBtn) contentView.addSubview(negativeBtn)
contentView.addSubview(confirmBtn) contentView.addSubview(confirmBtn)
// 默认选择否按钮 // 默认选择否按钮
didClickResponseBtn(btn: negativeBtn) response = false
questionLabel.snp.makeConstraints { make in titleLabel.snp.makeConstraints { make in
make.top.equalTo(contentView.snp.top).offset(12) make.top.equalTo(contentView.snp.top).offset(12)
make.left.equalToSuperview().offset(16) make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16) make.right.equalToSuperview().offset(-16)
...@@ -99,8 +104,8 @@ class YHDoubleChoiceQuestionCell: UITableViewCell { ...@@ -99,8 +104,8 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
negativeBtn.snp.makeConstraints { make in negativeBtn.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: btnWidth, height: btnHeight)) make.size.equalTo(CGSize(width: btnWidth, height: btnHeight))
make.left.equalTo(questionLabel) make.left.equalTo(titleLabel)
make.top.equalTo(questionLabel.snp.bottom).offset(12) make.top.equalTo(titleLabel.snp.bottom).offset(12)
make.bottom.equalToSuperview().offset(-16) make.bottom.equalToSuperview().offset(-16)
} }
...@@ -112,12 +117,16 @@ class YHDoubleChoiceQuestionCell: UITableViewCell { ...@@ -112,12 +117,16 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
} }
@objc func didClickResponseBtn(btn: UIButton) { @objc func didClickResponseBtn(btn: UIButton) {
let isConfirm = (btn.tag == confirmTag) response = (btn.tag == confirmTag)
if let responseBlock = responseBlock {
responseBlock(btn.tag==confirmTag)
}
}
func showResponse(_ isConfirm: Bool) {
confirmBtn.layer.borderColor = (isConfirm ? btnTitleSelectColor : .clear).cgColor confirmBtn.layer.borderColor = (isConfirm ? btnTitleSelectColor : .clear).cgColor
confirmBtn.setTitleColor((isConfirm ? btnTitleSelectColor : btnTitleDefaultColor), for: .normal) confirmBtn.setTitleColor((isConfirm ? btnTitleSelectColor : btnTitleDefaultColor), for: .normal)
negativeBtn.layer.borderColor = (isConfirm ? .clear : btnTitleSelectColor).cgColor negativeBtn.layer.borderColor = (isConfirm ? .clear : btnTitleSelectColor).cgColor
negativeBtn.setTitleColor((isConfirm ? btnTitleDefaultColor: btnTitleSelectColor), for: .normal) negativeBtn.setTitleColor((isConfirm ? btnTitleDefaultColor: btnTitleSelectColor), for: .normal)
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment