Thursday, August 25, 2011

Dyanamic adding and removing buttons


#### button Adding

- (IBAction)whisky:(id)sender {




if(j<21) {

CGRect rect = CGRectMake(100,20,70,20);
lbl1= [[[UILabel alloc] initWithFrame:rect] autorelease];
NSString *intString = [NSString stringWithFormat:@"%d", j-10];
[lbl1 setText:intString]; lbl1.tag=99; [self.view addSubview:lbl1];
button3 = [UIButton buttonWithType:UIButtonTypeCustom];
[button3 addTarget:self action:@selector(ratingAction2:)forControlEvents:UIControlEventTouchUpInside];
[button3 setBackgroundImage:[UIImage imageNamed:@"scanbutton1.png"] forState:UIControlStateNormal]; button3.tag = j;
button3.backgroundColor = [UIColor blueColor];
button3.frame = CGRectMake(120, width1, 35, 35);
[self.view addSubview:button3]; width1 = width1 -38; j++;
}
}


############### button delete based on tag ###########



- (IBAction)delWhis:(id)sender { if(j>1)
{
j--;

int f;
f=j;

[[self.view viewWithTag:f] removeFromSuperview];

//int b = button3.tag/10;




{
NSLog(@" whisky ration is %d",f);
width1 = width1 +38;


}


}


}

No comments:

FEEDJIT Live