【发布时间】:2014-08-09 05:12:31
【问题描述】:
我触摸 UIButton 的外部边界,然后在 UIButton 内拖动。状态未突出显示。
当我的手指刚刚触摸到 UIButton 的边界内时,如何设置 UIButton 被检测到突出显示?
例如:制作一个钢琴应用程序,当我触摸一个音符并向左或向右拖动时,它不仅会检测第一个声音,它还会检测我触摸的所有声音。
【问题讨论】:
标签: ios objective-c uibutton
我触摸 UIButton 的外部边界,然后在 UIButton 内拖动。状态未突出显示。
当我的手指刚刚触摸到 UIButton 的边界内时,如何设置 UIButton 被检测到突出显示?
例如:制作一个钢琴应用程序,当我触摸一个音符并向左或向右拖动时,它不仅会检测第一个声音,它还会检测我触摸的所有声音。
【问题讨论】:
标签: ios objective-c uibutton
尝试使用它。
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 的所有方法都可以访问它。
【讨论】: