ios 設定button 的高亮狀態
阿新 • • 發佈:2019-02-07
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake(0, 0, 200, 80)]; [button setTitle:@"button" forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonAction:forEvent:) forControlEvents:UIControlEventAllTouchEvents]; [self.view addSubview:button]; - (void)buttonAction:(id)sender forEvent:(UIEvent *)event{ UITouchPhase phase = event.allTouches.anyObject.phase; if (phase == UITouchPhaseBegan) { NSLog(@"press"); } else if(phase == UITouchPhaseEnded){ NSLog(@"release"); } }
2.可以重新寫系統的setHigh方法