当我触摸到内部边界时,如何让UIButton突出显示?

时间:2014-08-09 05:12:31

标签: ios objective-c uibutton

我触摸UIButton的外边界,然后在UIButton中拖动。国家不是重点。

当我的手指触摸UIButton内部时,如何设置UIButton是否突出显示?

例如:制作一个钢琴应用程序,当我触摸一个音符并向左或向右拖动时,不仅是第一个声音,它还能检测到我触摸过的所有声音。

1 个答案:

答案 0 :(得分:0)

尝试使用此功能。

  UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(5, 5, 50, 50)];
  myButton.backgroundColor = [UIColor greenColor];
myButton addTarget:self action:@selector(myFunction) forControlEvents:UIControlEventTouchDragEnter; //this method is fired when user touches the button and drags it from inside the bounds of the button.

-(IBAction)myFunction:sender(id){
    UIButton *myButton = (UIButton*)sender;
    myButton.backgroundColor = [UIColor redColor];
     myButton.highlighted = YES;
     [self checkForHighlight];
}

-(void)checkForHighlight {
   if(myButton.highlighted){
     myButton.backgroundColor = [UIColor blueColor];
    }
   }

您需要将UIButton * myButton声明为静态变量,以便VC的所有方法都可以访问它。