【问题标题】:Custom Button not showing my images for pushed state自定义按钮未显示我的推送状态图像
【发布时间】:2023-03-09 04:01:01
【问题描述】:

在代码中,我设置了以下内容: btnLogo.SetImage(UIImage.FromBundle("images/Zouak_logo_button.png"), UIControlState.Normal); btnLogo.SetImage(UIImage.FromBundle("images/Zouak_logo_button_pushed.png"), UIControlState.Selected);

我找不到 UIControlState.Pressed 或 Pushed 或任何类似的东西。当按钮被按下时,它当然不会显示我想要的图像版本。我需要在 Click 事件中手动执行此操作吗?

【问题讨论】:

    标签: iphone xamarin.ios


    【解决方案1】:

    我觉得你的语法有点奇怪,但我猜你想这样做:

    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:uiimg forState:UIControlStateHighlighted];
    

    【讨论】:

    • 当然,其中 uiimg = UIImage.FromBundle("images/Zouak_logo_button_pushed.png")。
    • 我看到了我的错误,我认为它是针对选定状态的,而不是突出显示的。谢谢。
    【解决方案2】:

    对所有州都这样做:

    UIImage *newNormalImage = [UIImage imageNamed:@"images/Zouak_logo_button.png"];
    [btnLogo setBackgroundImage:newNormalImage forState:UIControlStateNormal];
    // Image for highlighted state
    UIImage *newHighlightedImage = [UIImage imageNamed:@"mages/Zouak_logo_button_pushed.png"];
    [btnLogo setBackgroundImage:newHighlightedImage forState:UIControlStateHighlighted];
    // Image for selected state
    UIImage *newSelectedImage = [UIImage imageNamed:@"mages/Zouak_logo_button_pushed.png"];
    [btnLogo setBackgroundImage:newSelectedImage forState:UIControlStateSelected];
    

    【讨论】:

      猜你喜欢
      • 2013-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      相关资源
      最近更新 更多