Ios 将图像从UIImageView复制到UIView
我希望将图像从UIImageView复制到UIView 我已经为UIImageView编写了滑动手势来选择图像,并且需要知道当用户单击添加按钮时如何将多个图像从UIImageView复制到UIView。我希望用户能够复制到UIView不同的图像。我以后会安排的Ios 将图像从UIImageView复制到UIView,ios,objective-c,uiview,uiimageview,Ios,Objective C,Uiview,Uiimageview,我希望将图像从UIImageView复制到UIView 我已经为UIImageView编写了滑动手势来选择图像,并且需要知道当用户单击添加按钮时如何将多个图像从UIImageView复制到UIView。我希望用户能够复制到UIView不同的图像。我以后会安排的 - (IBAction)handleSwipe:(UIGestureRecognizer *)sender { //NSLog(@"swipe"); NSArray *images=[[NSArray alloc] in
- (IBAction)handleSwipe:(UIGestureRecognizer *)sender {
//NSLog(@"swipe");
NSArray *images=[[NSArray alloc] initWithObjects:
@"all_LE2_Series_capacitor.jpg",
@"all_LE2_Series_inductor.jpg",
@"all_LE2_Series_msline.jpg",
@"all_LE2_Series_resistor.jpg",
@"all_LE2_Short_stub.jpg", nil];
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
switch (direction){
case UISwipeGestureRecognizerDirectionLeft: imageIndex++;
break;
case UISwipeGestureRecognizerDirectionRight: imageIndex--;
break;
default:
break;
}
imageIndex = (imageIndex < 0) ? ([images count] -1):
imageIndex % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}
- (IBAction)Add:(UIButton *)sender {
dropTarget.center = imageView.center;
[self.view addSubview:dropTarget];
}
-(iAction)handleSwipe:(UIgestureRecognitor*)发送方{
//NSLog(“刷卡”);
NSArray*图像=[[NSArray alloc]initWithObjects:
@“所有LE2系列电容器.jpg”,
@“所有LE2系列电感.jpg”,
@“all_LE2_Series_msline.jpg”,
@“所有LE2系列电阻器.jpg”,
@“all_LE2_Short_stub.jpg”,无);
UISweepGestureRecognitzerDirection=[(UISweepGestureRecognitzer*)发送方方向];
开关(方向){
案例UISweepGestureRecognitizerDirectionLeft:imageIndex++;
打破
案例UISweepGestureRecognitizerDirectionRight:imageIndex--;
打破
违约:
打破
}
imageIndex=(imageIndex<0)?([图像计数]-1):
imageIndex%[图像计数];
imageView.image=[UIImage ImageName:[images objectAtIndex:imageIndex]];
}
-(iAction)添加:(UIButton*)发送者{
dropTarget.center=imageView.center;
[self.view addSubview:dropTarget];
}
图形用户界面设计
要更改UIView背景图像,可以使用
myview.backgroundColor = [UIColor colorWithPatternImage:myimage];
这是我的看法: 首先,每次在
handlesweep:
内,您都在images
数组中添加不必要的图像。将images
设为类级属性并添加一次图像,可能是在loadView:
方法中
下一步,保留当前的imageIndex
。将此属性移动到类级别属性(如果尚未存在)
最后,在视图中,按如下方式添加所选图像:
UIImageView *selectedImageView = [[UIImageView alloc] initWithImage:self.images[self.imageIndex]];
[self.view addSubView:selectedImageView]
“将图像从
UIImageView
复制到UIView
并附加值”是什么意思?哪个附加值?我不想更改背景,而且它也超出UIView大小错误如下:在类型为“ViewController”的对象上找不到属性“imageIndex”。“UIView”没有可见的@interface声明选择器“addSubView”。您需要创建一个类级属性,如@property(非原子,赋值)NSInteger imageIndex代码>以便能够使用它。我以为您已经在这样做了。抱歉,错误是:在“ViewController”类型的对象上找不到属性“images”。第二个错误是:“UIView”没有可见的@interface声明选择器“addSubView”。我希望在UIView中添加多个图像,而不仅仅是一个图像