【问题标题】:History in calculator with photos instead of signs计算器中的历史,带有照片而不是符号
【发布时间】:2018-04-10 08:46:25
【问题描述】:

我有代码可以在计算器中显示历史记录,但符号(+、-、×、÷)取自“案例”(照片 1)

我怎样才能让历史中的符号(+,-,×,÷)由我设置的图片显示(照片2)

@IBAction func equalitySignPressed(sender: UIButton) {
    if stillTyping {
        secondOperand = currentInput
    }
    dotIsPlaced = false

    addHistory(text: operationSign + displayResultLabel.text!)

    switch operationSign {

    case "+":
        operateWithTwoOperands{$0 + $1}
    case "-":
        operateWithTwoOperands{$0 - $1}
    case "×":
        operateWithTwoOperands{$0 * $1}
    case "÷":
        if secondOperand == 0 {
            Error.text = NSLocalizedString("Division by Zero", comment: "")
            break
        } else {
            operateWithTwoOperands{$0 / $1}
        }
    default: break
    }
}

添加历史记录:

func addHistory(text: String){
    //Add text
    resultLabelText.text =  resultLabelText.text! + "" + text
}

【问题讨论】:

    标签: ios swift calculator


    【解决方案1】:

    不需要图像或属性字符串。您可以将 Unicode 字符 (U+20E3 - 组合封闭键帽)与各种数学符号一起使用:+-×÷=.

    将这些放在一起给出:+⃣-⃣×⃣÷⃣=⃣

    【讨论】:

    • 我不明白这是怎么实现的?
    • 只需将这些符号放入您的代码中并根据需要显示它们。
    【解决方案2】:

    您可以在显示历史条目时使用NSAttributedString。属性字符串可以包含图像,例如 https://www.hackingwithswift.com/example-code/system/how-to-insert-images-into-an-attributed-string-with-nstextattachment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-04
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      相关资源
      最近更新 更多