开发者

setContentEdgeInsets for different states of a UIButton?

开发者 https://www.devze.com 2023-02-06 11:08 出处:网络
I\'m trying to give a button a depressed look, and to achieve that I need to bump down the title of the button when it\'s pressed. I think contentEdgeInsets is what I need, but I can\'t figure out how

I'm trying to give a button a depressed look, and to achieve that I need to bump down the title of the button when it's pressed. I think contentEdgeInsets is what I need, but I can't figure out how to set different values depending on the buttons state.

This works:

introButton.contentEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 0);

This, however, doesn't:

[introButton setContentEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 0) forState:UIControlStateNormal]; 
// warning: 'UIButton' may not respond to 开发者_运维知识库'-setContentEdgeInsets:forState:'


The debugger is giving you the answer: UIButton' doesn't respond to '-setContentEdgeInsets:forState:.

contentEdgeInsets is a property for UIButton, there doesn't appear to be any class method to do what you're asking.

I think you're going to have to subclass UIButton and implement a delegate to tell you when the button is pressed and update the button accordingly.

0

精彩评论

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