开发者

How to highlight a button when it is pressed

开发者 https://www.devze.com 2023-01-13 09:24 出处:网络
This seems to work, but then the program crashes right after the button get highlighted. -(IBAction) buttonPressed: (id) sender

This seems to work, but then the program crashes right after the button get highlighted.

-(IBAction) buttonPressed: (id) sender
{
    [sender setHighlighted:YES];    
}

How should this be diffeent? What would it look like if I wanted to highlight the button if it was not previously highlighted, and return the button to i开发者_开发知识库ts normal state if it was?


The answer is probably do nothing. NSButton in Cocoa handles this for free; it would surprise me if UIButton didn't do the same.

If the answer is not do nothing, it's to set a different background image for the relevant control states. If you're already customizing it, then you'll want to do this anyway.

Either way, you should not handle this in your action.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号