0
안녕하세요 저는 iPhone 개발에 익숙하지 않습니다.
버튼 클릭시 프로그래밍 방식으로 UIImageViews를 생성합니다. 버튼을 클릭 할 때마다 같은 위치에서 그려집니다. 이미지 그리기 코드는 다음과 같습니다. UIScrollview에 표시된 이미지를 확인하십시오.
- (IBAction)Button
{
arrayOfImages = [[NSMutableArray alloc]init];
float x = 15.0,y = 15.0, width = 100.0, height = 100;
CGRect frame = CGRectMake(x, y, width, height);
int i= 0;
if ([shape isEqualToString:@"Rectangle"])
{
UIGraphicsBeginImageContext(frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2.0);
CGRect main =CGRectMake(x, y, 70.0, 30.0);
CGContextFillRect(context, main);
CGRect topSeat1 = CGRectMake(15.0, 0.0, 15.0, 13.0);
CGRect topSeat2 = CGRectMake(42.5, 0.0, 15.0, 13.0);
CGRect topSeat3 = CGRectMake(70.0, 0.0, 15.0, 13.0);
CGRect leftSeat = CGRectMake(0.0, 22.5, 13.0, 15.0);
CGRect rightSeat = CGRectMake(87.0, 22.5, 13.0, 15.0);
[[UIColor redColor]set];
//UIRectFill(main);
UIRectFill(topSeat1);
UIRectFill(topSeat2);
UIRectFill(topSeat3);
UIRectFill(leftSeat);
UIRectFill(rightSeat);
UIRectFrame(main);
[[UIColor blackColor]set];
UIRectFrame(topSeat1);
UIRectFrame(topSeat2);
UIRectFrame(topSeat3);
UIRectFrame(leftSeat);
UIRectFrame(rightSeat);
UIImage * images = [[UIImage alloc]init];
images = UIGraphicsGetImageFromCurrentImageContext();
UIImageView* myImage=[[UIImageView alloc]initWithFrame:frame];
[myImage setImage:images];
myImage.tag= i;
i++;
UIGraphicsEndImageContext();
[self.view addSubview:myImage];
[arrayOfImages addObject:myImage];
[myImage setUserInteractionEnabled:YES];
}
}
내가 원하는 모든
내가 이미 존재하는 경우 UIImageView에 그 자리에서 그려 있는지 확인해야 버튼을 클릭하면 다음 조금 멀리에서있는 UIImageView를 그리는 것입니다.몇 가지 코드로 도와 주시면 감사하겠습니다.
를 볼 수 있습니다. – Hanny
@Hanny : 답변을 수정했습니다. –