IOS: Images and click events

Source: Internet
Author: User

Question: How do you differentiate which picture is the point?

////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>//View Controller Objects@interfaceHelloworldviewcontroller:uiviewcontroller@end@implementationHelloworldviewcontroller-(void) loadview{//Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview; Uiimageview*imageview =[[uiimageview Alloc]initwithframe:cgrectmake ( -, -, -, -)]; Imageview.image= [UIImage imagenamed:@"100.png"]; Imageview.userinteractionenabled=YES; UITapGestureRecognizer*singletap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (uesrclicked:)];        [ImageView Addgesturerecognizer:singletap]; Uiimageview*imageview2 =[[uiimageview Alloc]initwithframe:cgrectmake ( -, -, -, -)]; Imageview2.image= [UIImage imagenamed:@"100.png"]; Imageview2.userinteractionenabled=YES; UITapGestureRecognizer*SINGLETAP2 =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (uesrclicked:)];        [ImageView2 ADDGESTURERECOGNIZER:SINGLETAP2];    [Contentview Addsubview:imageview]; [Contentview addsubview:imageview2];}-(void) Uesrclicked: (ID) sender{//NSLog (@ "%@", ((uiimageview*) ((UITapGestureRecognizer *) sender). View). image);NSLog (@"%@", sender);}@end//Delegate Object@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window;//must be declared as a property, declared as a local variable, cannot draw a view, display as a black screen@end@implementationhelloworldappdelegate@synthesizewindow;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Helloworldviewcontroller*viewcontroller =[[Helloworldviewcontroller alloc]init]; Self.window.rootViewController=Viewcontroller; [Self.window makekeyandvisible];}@end//Program EntryintMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}

IOS: Images and click events

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.