我想知道如何通过单击按钮来更改标签上的文本,我有 2 个按钮,分别名为添加和减号,如果我们单击添加按钮,每次单击时,它会从 1 增加到 10,如果我们单击在减号按钮上,它应该从 1-10 减少,
我尝试做一些事情,如下所示
-(IBAction) addQuantity
{
for (int i=1;i<11; i++)
{
[m_label setText:[NSString stringWithFormat:@"%i",i]];
}
}
请 friend 们告诉我如何进行,
问候 兰 git
最佳答案
NSInteger counter = 0;
-(IBAction) addQuantity
{
if (counter > 9 )
return;
[m_label setText:[NSString stringWithFormat:@"%d",++counter]];
}
-(IBAction) minusQuantity
{
if (counter < 1 )
return;
[m_label setText:[NSString stringWithFormat:@"%d",--counter]];
}
关于ios - 单击按钮更改标签上的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7752493/