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

// 双项选择题

parent b3264fb0
......@@ -20,10 +20,12 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
let confirmTag = 9527
let negativeTag = 9528
var question:String? {
var responseBlock:((Bool)->Void)?
var title:String? {
didSet {
if let question = question {
if let question = title {
let str = "*"+question
let attributes: [NSAttributedString.Key: Any] = [
.font: UIFont.PFSCR(ofSize: 14),
......@@ -32,15 +34,18 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
let questionAttrStr = NSMutableAttributedString(string: str, attributes: attributes)
let starRange = NSRange(location: 0, length: 1)
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()
label.numberOfLines = 0
label.textColor = UIColor(hexString:"#333333")
......@@ -84,14 +89,14 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
self.selectionStyle = .none
question = " 1、是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪? "
contentView.addSubview(questionLabel)
title = " 1、是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪?是否曾在香港或其他地方因任何罪行或违法行为被定罪? "
contentView.addSubview(titleLabel)
contentView.addSubview(negativeBtn)
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.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
......@@ -99,8 +104,8 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
negativeBtn.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: btnWidth, height: btnHeight))
make.left.equalTo(questionLabel)
make.top.equalTo(questionLabel.snp.bottom).offset(12)
make.left.equalTo(titleLabel)
make.top.equalTo(titleLabel.snp.bottom).offset(12)
make.bottom.equalToSuperview().offset(-16)
}
......@@ -112,12 +117,16 @@ class YHDoubleChoiceQuestionCell: UITableViewCell {
}
@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.setTitleColor((isConfirm ? btnTitleSelectColor : btnTitleDefaultColor), for: .normal)
negativeBtn.layer.borderColor = (isConfirm ? .clear : btnTitleSelectColor).cgColor
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