我一直在尝试创建一个for
循环,UILabel.text
将其合并到一个UIImage
然后将其保存到一个实例中,然后当第二次进入for
循环时,它将结果保存在不同的实例中。
我面临的问题是它正在保存第一个UIImage
但质量低下并跳过第二个。我什至尝试UIImage
在按钮操作中执行保存代码,但仍然无效。
-(void)CreateTheImage{
UIImage * img = [UIImage imageNamed:@"SquareBackground.jpg"];
UIGraphicsBeginImageContext(_imgView.bounds.size);
int Counter = 0;
for (UIView * view in [_imgView subviews]){
[view removeFromSuperview];
}
NSString *txt1 = @"Test";
NSString *txt2 = @"Worked Well";
[array addObject:txt1];
[array addObject:txt2];
UILabel *lbl = [[UILabel alloc]init];
NSLog(@"%i",[array count]);
NSLog(@"Before the loop");
for (int x = 0; x < [array count]; x++) {
NSLog(@"Entered the loop");
NSLog(@"x = %i",x);
lbl.text = [array objectAtIndex:x];
NSLog(@"lbl.text = %@",[array objectAtIndex:x]);
lbl.textAlignment = NSTextAlignmentCenter;
[lbl setBackgroundColor:[UIColor clearColor]];
lbl.font = [UIFont boldSystemFontOfSize:16];
[lbl setFrame:CGRectMake(20,112.5, 260, 75)];
[_imgView addSubview:lbl];
[_imgView bringSubviewToFront:lbl];
[_imgView setImage:img];
[_imgView.layer renderInContext:UIGraphicsGetCurrentContext()];
Counter = x+1;
NSLog(@"counter = %i",Counter);
switch (Counter) {
case 1:
NSLog(@"swintch case 1");
newImage1 = UIGraphicsGetImageFromCurrentImageContext();
break;
case 2:
NSLog(@"swintch case 2");
newImage2 = UIGraphicsGetImageFromCurrentImageContext();
break;
default:
break;
}
NSLog(@"after switch");
UIGraphicsEndImageContext();
}
//To save the picture in the album
UIImageWriteToSavedPhotosAlbum(newImage1, nil, nil, nil);
UIImageWriteToSavedPhotosAlbum(newImage2, nil, nil, nil);
NSLog(@"After the loop");
}
此外,当我在 iPhone 上运行此方法时,它会给我一个警告,即
CreatingVideo[334]:CGContextSaveGState:无效上下文 0x0。这是一个严重的错误。此应用程序或它使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是出于礼貌:请解决此问题。这将成为即将到来的更新中的致命错误。