UIButton SetImage属性仅在单击时显示图像

时间:2013-07-15 17:36:16

标签: xamarin.ios mono uibutton

我有一个内部有图像的UIButton。 单击按钮时图像仅显示,但无论按钮的状态如何,我都希望显示图像。

this.SetImage(image, UIControlState.Normal);

当我在按钮上单击鼠标时,图像显示出来。我尝试过其他状态 - 例如,UIControlState.Highlighted,尽管在这种状态下图像根本不会显示。

1 个答案:

答案 0 :(得分:0)

UIButton *m_btnSample = [UIButton buttonWithType:UIButtonTypeCustom];
    [m_btnSample setFrame:CGRectMake(200, 300, 200, 40)];
    [m_btnSample setImage:[UIImage imageNamed:@"smiley1.jpg"] forState:UIControlStateNormal];
    [self.view addSubview:m_btnSample];

根据我上面编写的代码,无论状态如何,图像都会被设置