如果使用Xcode制作iOS计算器,我该如何添加小数点按钮? [英] If using Xcode to make an iOS calculator, how would I add a decimal button?
问题描述
如何添加小数点按钮,所以我不需要做整数?如果我想要任何十进制数字,如1.2或100.4或3.0或类似的东西,我如何将它添加到我正在制作的计算器?
How to add a decimal button so I don't have to do whole numbers? If i wanted any decimal number like 1.2 or 100.4 or 3.0 or anything like that, how would I add it to the calculator I'm making?
推荐答案
你没有在你的问题中给我很多信息。其他按钮如何工作?
You're not giving me much information in your question. How do the other buttons work?
如果我正在制作计算器,我会在顶部显示一个标签,显示当前的读数。按下数字按钮,我会用最后的数字更新标签。
If I was making a calculator I would have a label at the top showing the current reading. On press of a number button I would update the label with the number at the end.
对于小数点按钮,你只需添加一个。到标签的末尾。您可能希望拥有一个全局变量 BOOL hasDecimalPlace
并将其设置为true,以便知道是否已存在小数位。只需记住在清除视图或进行计算或类似操作时再将其设置为false。
For a decimal button you just add a . to the end of the label. You might want to have a global variable BOOL hasDecimalPlace
and set it to true so you know if there is already a decimal place. Just remember to set it to false again when you clear the view or do a calculation or similar.
这篇关于如果使用Xcode制作iOS计算器,我该如何添加小数点按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!