计算器中的历史记录用照片代替符号
History in calculator with photos instead of signs
我有在计算器中显示历史记录的代码,但符号 (+, -, ×, ÷) 取自 "case"(照片 1)
怎样才能让历史上的符号(+,-,×,÷)显示在我设置的图片中(图2)
@IBAction func equalitySignPressed(sender: UIButton) {
if stillTyping {
secondOperand = currentInput
}
dotIsPlaced = false
addHistory(text: operationSign + displayResultLabel.text!)
switch operationSign {
case "+":
operateWithTwoOperands{[=10=] + }
case "-":
operateWithTwoOperands{[=10=] - }
case "×":
operateWithTwoOperands{[=10=] * }
case "÷":
if secondOperand == 0 {
Error.text = NSLocalizedString("Division by Zero", comment: "")
break
} else {
operateWithTwoOperands{[=10=] / }
}
default: break
}
}
添加历史:
func addHistory(text: String){
//Add text
resultLabelText.text = resultLabelText.text! + "" + text
}
您可以在显示历史条目时使用 NSAttributedString
。属性字符串可以包含图像,例如 https://www.hackingwithswift.com/example-code/system/how-to-insert-images-into-an-attributed-string-with-nstextattachment
不需要图像或属性字符串。您可以将 Unicode 字符 ⃣
(U+20E3 - 组合封闭键帽)与各种数学符号一起使用:+
、-
、×
、÷
。 =
.
将这些放在一起得到:+⃣
、-⃣
、×⃣
、÷⃣
、=⃣
。
我有在计算器中显示历史记录的代码,但符号 (+, -, ×, ÷) 取自 "case"(照片 1)
怎样才能让历史上的符号(+,-,×,÷)显示在我设置的图片中(图2)
@IBAction func equalitySignPressed(sender: UIButton) {
if stillTyping {
secondOperand = currentInput
}
dotIsPlaced = false
addHistory(text: operationSign + displayResultLabel.text!)
switch operationSign {
case "+":
operateWithTwoOperands{[=10=] + }
case "-":
operateWithTwoOperands{[=10=] - }
case "×":
operateWithTwoOperands{[=10=] * }
case "÷":
if secondOperand == 0 {
Error.text = NSLocalizedString("Division by Zero", comment: "")
break
} else {
operateWithTwoOperands{[=10=] / }
}
default: break
}
}
添加历史:
func addHistory(text: String){
//Add text
resultLabelText.text = resultLabelText.text! + "" + text
}
您可以在显示历史条目时使用 NSAttributedString
。属性字符串可以包含图像,例如 https://www.hackingwithswift.com/example-code/system/how-to-insert-images-into-an-attributed-string-with-nstextattachment
不需要图像或属性字符串。您可以将 Unicode 字符 ⃣
(U+20E3 - 组合封闭键帽)与各种数学符号一起使用:+
、-
、×
、÷
。 =
.
将这些放在一起得到:+⃣
、-⃣
、×⃣
、÷⃣
、=⃣
。