如何添加“1”到 XCode 中的 UILabel
我需要将值“1”添加到 UILabel 视图中已有的任何值上。例如,如果 UILabel 的值为 2,我需要加一使其变为 3。我该怎么做?
谢谢,
詹姆斯
I need to add the value "1" onto whatever value is already in a UILabel view. For example, if the value of the UILabel were 2, I need to plus one to make it 3. How can I do this?
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSString
有一个名为intValue
的便捷方法,您可以像这样使用它:对于后续问题,只需使用
if
语句:或也许你的意思是
NSString
has a handy method calledintValue
, which you can use like this:For your follow-up question, simply use an
if
statement:or maybe you mean
在 Swift 2.0 中,我使用:
我尝试将其放在
函数的顶部并重用它,但它不喜欢那样。每次我想增加标签值时都必须使用这两行。
希望这对某人有帮助!
In Swift 2.0 I used:
I tried putting
at the top of the function and reusing it but it didn't like that. Had to use both lines each time I wanted to increase the label value.
Hope this helps someone!