我尝试使用UibuttonTyPecustom创建一个Uibutton。然后之后使用以下方法调整外观

[sendButton setImage:[UIImage imageNamed:@"sendButtonOff.png"] forState:UIControlStateNormal];
[sendButton setImage:[UIImage imageNamed:@"sendButtonOn.png"] forState:UIControlStateHighlighted];      
[sendButton setImage:[UIImage imageNamed:@"sendButtonDisabled.png"] forState:UIControlStateDisabled];

但是,问题是,一旦您开始将UIIMAGE设置为各州,则设置不再有效。我认为settitle只能与非uibuttytypecustom一起使用?这意味着我要么必须将文本本身放入图像本身(不是很健壮),要么子类并在视图中添加uilabel?听起来像是很多工作:(有什么想法吗?

有帮助吗?

解决方案

如果您希望标题在图像上显示,请尝试使用以下方式:

[sendButton setBackgroundImage:[UIImage imageNamed:@"sendButtonOff.png"] forState:UIControlStateNormal];
[sendButton setBackgroundImage:[UIImage imageNamed:@"sendButtonOn.png"] forState:UIControlStateHighlighted];      
[sendButton setBackgroundImage:[UIImage imageNamed:@"sendButtonDisabled.png"] forState:UIControlStateDisabled];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top