开发者

Changing text on label with button click

开发者 https://www.devze.com 2023-04-12 22:39 出处:网络
I want to know how we can change text on label with button click,i have 2 buttons named add and minus,if we click on add button,on each click ,it will increase from 1-10,and if we click on minus butto

I want to know how we can change text on label with button click,i have 2 buttons named add and minus,if we click on add button,on each click ,it will increase from 1-10,and if we click on minus button ,it should reduce from 1开发者_如何学C-10,

I tried to do some stuff,which is below

-(IBAction) addQuantity
{
    for (int i=1;i<11; i++)
    {
        [m_label setText:[NSString stringWithFormat:@"%i",i]];
    }

}

please friends explain me how to proceed,

Regards Ranjit


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]];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消