.h ファイルにこれを追加します
NSString * LRStr;
int count;
int y;
および.mファイルで
-(void)viewDidLoad
{
LRStr = @"left";
count=0;
y=0;
}
- (IBAction)addView:(id)sender {
if(count == 2 )
{
y=y+60;
count = 0;
}
if ([LRStr isEqualToString:@"left"])
{
UIView * bGView = [[UIView alloc] init];
bGView.frame = CGRectMake(10,y,50,50);
bGView.backgroundColor = [UIColor clearColor];
bGView.alpha = 0.8 ;
[self.view addSubview:bGView];
UILabel * alabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
alabel.text = @"Write here";
alabel.adjustsFontSizeToFitWidth = NO;
alabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
alabel.backgroundColor = [UIColor clearColor];
[bGView addSubview:alabel];
LRStr = @"right"
}else
{
UIView * bGView = [[UIView alloc] init];
bGView.frame = CGRectMake(260,y,50,50);
bGView.backgroundColor = [UIColor clearColor];
bGView.alpha = 0.8 ;
[self.view addSubview:bGView];
UILabel * alabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
alabel.text = @"Write here";
alabel.adjustsFontSizeToFitWidth = NO;
alabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
alabel.backgroundColor = [UIColor clearColor];
[bGView addSubview:alabel];
LRStr = @"left"
}
count++;
}