gpt4 book ai didi

c# - 将 "SetTitleTextAttributes"应用于后推按钮

转载 作者:行者123 更新时间:2023-11-29 13:10:34 25 4
gpt4 key购买 nike

所以我有 vc A 和 vc B。当我执行从 A 到 B 的推送转场时,会自动创建一个后退按钮。这很好,但我想使用 SetTitleTextAttributes 将此按钮的文本颜色更改为黑色。

通过阅读与此相关的其他问题,我了解到您必须编辑将出现在 vc A 中的 vc B 中的后退按钮。像这样的东西:

在 vc A 上:

this.NavigationController.NavigationItem.BackBarButtonItem.SetTitleTextAttributes (textAttrButton, UIControlState.Normal);

在某些问题上,他们说要将其放在 viewWillAppear 中,其他人则说就在您对 vc B 执行 segue 之前。在这两种情况下,我都收到以下错误:

object reference not set to an instance of an object

这是在 vc B 上:

enter image description here

最佳答案

更好的选择是为此使用 UIAppearance。适用于整个应用中的所有 UIBarButtonItems,但需要 iOS。

UIBarButtonItem.Appearance.SetTitleTextAttributes(new TextAttributes { TextColor = UIColor.Black }, UIControlState.Normal);

关于c# - 将 "SetTitleTextAttributes"应用于后推按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17490758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com