gpt4 book ai didi

objective-c - 使用 NSStepper 设置上限值而不是递增值

转载 作者:行者123 更新时间:2023-12-03 17:57:12 34 4
gpt4 key购买 nike

我正在使用 NSStepperNSTextField。用户可以使用文本字段设置值,也可以使用 NSStepper 更改值。我将使用下面的示例引用我的问题:
假设我的步进器的当前值为 4,步进器的增量值为 2: enter image description here

单击 NSStepper 上的向上箭头后,值变为:
enter image description here

现在假设当前值为 4.5,即:
enter image description here

使用向上箭头后,值变为:
enter image description here

我要求的是,当当前值为4.5时,使用向上箭头后,该值变为6而不是6.5

任何实现这一目标的想法都将受到高度赞赏!

最佳答案

What I require is that when the current value is 4.5, after using the UP arrow, the value becomes 6 instead of 6.5

很难确切地说出您在问什么,但可以猜测:听起来您想删除数字的小数部分并按定义的步长量 (2) 递增。您可以通过floor()函数来完成此操作。 See here for other Objective-C math functions

double floor ( double ) - removes the decimal part of the argument

NSLog(@"res: %.f", floor(3.000000000001)); 
//result 3
NSLog(@"res:%.f", floor(3.9999999));
//result 3

关于objective-c - 使用 NSStepper 设置上限值而不是递增值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538129/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com