-1

我从 UIWebView 获取触摸位置坐标并显示带有坐标的按钮。它与坐标匹配一起工作。所以,我需要增加按钮。我没有使用 Array 作为按钮。当我从 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];

    }
4

1 回答 1

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]; 
 }
于 2013-10-28T04:36:52.787 回答