UIWebView上的删除按钮

时间:2013-10-28 04:22:52

标签: ios uiwebview uibutton nsmutablearray

我从UIWebView获取触摸位置坐标并显示带坐标的按钮。它正在使用坐标匹配。所以,我需要增加按钮。我没有使用Array for按钮。当我从UIWebView删除特定按钮时,它删除所有按钮。我应该使用NSMutableArray吗?这里x& y是浮点值中的触摸点坐标

if(x && y){

        NSLog(@"x is %f",x);
        NSLog(@"y is %f",y);

        button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button1 addTarget:self
                    action:@selector(click1:)
          forControlEvents:UIControlEventTouchDown];
        [button1 setTitle:@"click" forState:UIControlStateNormal];

        button1.frame = CGRectMake(x, y, 30.0, 20.0);

       // [btnArray addObject:button1];

        button1.tag = gTag;
        gTag++;
        [wbCont.scrollView  addSubview:button1];



    }

删除按钮:

-(void)recycle:(id)sender{


    for(int i=1;i<gTag;i++){


        [[wbCont.scrollView  viewWithTag:i] removeFromSuperview];

    }

1 个答案:

答案 0 :(得分:2)

-(void)click1:(id)sender{ 
   UIButton *mainBtn = (UIButton *)sender; 
   int mainTag = mainBtn.tag; 
   txtview = [[UITextView alloc]initWithFrame:CGRectMake(0,0,320,568)]; 
   txtview.font = [UIFont fontWithName:@"Helvetica" size:12]; 
   txtview.font = [UIFont boldSystemFontOfSize:12]; 
   txtview.backgroundColor = [UIColor whiteColor]; 
   txtview.scrollEnabled = YES; 
   txtview.pagingEnabled = YES; 
   txtview.editable = YES; 
   txtview.tag = mainTag*1000; 

   for(int i=0; i<[textArray count];i++){ 
       txtview.text=[textArray objectAtIndex:i]; 
   } 
   [self.view addSubview:txtview]; 


   button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
  [button addTarget:self action:@selector(done:) forControlEvents:UIControlEventTouchDown]; 
  [button setTitle:@"Done" forState:UIControlStateNormal]; 
  button.frame = CGRectMake(240.0, 20.0, 60.0, 40.0); 
  [txtview addSubview:button]; 

  recyclebtn=[UIButton buttonWithType:UIButtonTypeCustom]; 
  recyclebtn.tag = mainBtn.tag; 
  [recyclebtn addTarget:self action:@selector(recycle:)  forControlEvents:UIControlEventTouchDown]; 
  [recyclebtn setImage:[UIImage imageNamed:@"recycle.png"] forState:UIControlStateNormal]; 
  recyclebtn.frame=CGRectMake(0, 10, 30, 30); 
  [txtview addSubview:recyclebtn]; 


}



 -(void)recycle:(id)sender { 
     UIButton *btnTemp = (UIButton *)sender; 
     [[wbCont.scrollView viewWithTag:btnTemp.tag] removeFromSuperview]; 
     int txtTag = btnTemp.tag*1000; 
     [[self.view viewWithTag: txtTag] removeFromSuperview]; 
 }