将引脚添加到自定义图像

时间:2012-10-11 08:42:44

标签: iphone ios5 xcode4.2

如何在自定义图像上添加可点击的针脚或类似针脚?让用户在图像或视图上单击图钉(可能是文本框)时添加注释。

在我的代码中,我在图像上添加了静态弹出窗口 我希望我能找到方法让用户在点击图像的任何部分时让他添加别针或类似弹出窗口。

  I use this code to add popup to the image 
(part of the code ) self.visiblePopTipViews = [NSMutableArray array];

    self.contents = [NSDictionary dictionaryWithObjectsAndKeys:
                     // Rounded rect buttons
                     @"Play Ground", [NSNumber numberWithInt:1],
                     @"HeadMaster", [NSNumber numberWithInt:2],
                     @"Science Faculty", [NSNumber numberWithInt:3],
                     @"Accounting Faculty", [NSNumber numberWithInt:4],
                     @"Economy Faculty", [NSNumber numberWithInt:5],
                     @"Cultive Faculty", [NSNumber numberWithInt:6],
                     @"Tourisim Faculty", [NSNumber numberWithInt:7],
                     @"Swimming Pool ", [NSNumber numberWithInt:8],
                     @"Medicine Faculty", [NSNumber numberWithInt:9],
                     @"Engeneering Faculty", [NSNumber numberWithInt:10],
                     @"IT Faculty", [NSNumber numberWithInt:11],
                     nil];

    // Array of (backgroundColor, textColor) pairs.
    // NSNull for either means leave as default.
    // A color scheme will be picked randomly per CMPopTipView.
    self.colorSchemes = [NSArray arrayWithObjects:
                         [NSArray arrayWithObjects:[NSNull null], [NSNull null], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor darkTextColor], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor blueColor], nil],
                         [NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
                         nil];
     scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    scroll.backgroundColor = [UIColor blackColor];
    scroll.delegate = self;

     zoomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, scroll.contentSize.width, scroll.contentSize.height)];
    zoomView.backgroundColor = [UIColor whiteColor];

    image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]];

    scroll.contentSize = image.frame.size;
    [scroll addSubview:image ] ; 

    UIButton *playGround = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [playGround addTarget:self 
                   action:@selector(buttonAction:)
         forControlEvents:UIControlEventTouchDown];
    [playGround setTitle:@"playGround" forState:UIControlStateNormal];
    playGround.tag = 1 ; 
    playGround.frame = CGRectMake(290.0, 170.0, 80.0, 40.0);
    [image addSubview:playGround];

    UIButton *masterBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [masterBtn addTarget:self 
                  action:@selector(buttonAction:)
        forControlEvents:UIControlEventTouchDown];
    [masterBtn setTitle:@"Presidency" forState:UIControlStateNormal];
    masterBtn.tag = 2 ; 
    masterBtn.frame = CGRectMake(250.0, 270.0, 60.0, 30.0);
    [image addSubview:masterBtn];

1 个答案:

答案 0 :(得分:3)

UIImageView* marker = [[UIImageView alloc] initWithImage: myMarkerImage];
[marker setCenter: CGPointMake(250,150)];
[myScrollView addSubview: marker];