当我们点击栏按钮时,是否可以更改它的背景图像?

发布于 2024-09-26 02:05:27 字数 111 浏览 1 评论 0原文

我有一个 barbuttonitem,我使用带有图像的自定义按钮对其进行了自定义。我想每次点击后改变这个图像。就像开和关一样。一旦我点击它,它将显示关闭图像。然后它会再次打开图像。

是否可以?

I have a barbuttonitem which i have customised using a custom button with an image. I want to change this image everytime after I click it. Like on and off. Once I click it it will show OFF image. Then again it will go ON image.

Is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆凄美了谁 2024-10-03 02:05:27

是的。在您的目标方法中,只需更改 UIBarButtonItem

- (void)toolbarButtonPressedAwesomeMethod {

    Do awesome stuff...

    // Change the button here…
    UIBarButtonItem *bbi = [[[UIBarButtonItem alloc] init…

    // Set it in the view
    [self.navigationItem setRightBarButtonItem:bbi];
}

Yes. In your target method just change out the UIBarButtonItem

- (void)toolbarButtonPressedAwesomeMethod {

    Do awesome stuff...

    // Change the button here…
    UIBarButtonItem *bbi = [[[UIBarButtonItem alloc] init…

    // Set it in the view
    [self.navigationItem setRightBarButtonItem:bbi];
}
绝情姑娘 2024-10-03 02:05:27

yourButton.image = [UIImage imageNamed:@"yourImage"];

UIBarItem 文档

yourButton.image = [UIImage imageNamed:@"yourImage"];

UIBarItem Documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文