ios – UISegmentedControl仅在重新访问ViewController时更改文本颜色

ios – UISegmentedControl仅在重新访问ViewController时更改文本颜色,第1张

概述更新回答.由我. 目前我的UISegmentedControl的文本颜色变化有问题;它需要在第一次加载时使用UIControlStateSelected进行更改.代码有效,但只是有条件的.当您在导航栏上使用分段控件访问页面,点击后退按钮,然后再次访问该页面时,它可以正常工作.我假设这里有继承问题.让我解释.. 分段控件的位置位于导航栏的顶部. 包含SegmentedControl的ViewCont 更新回答.由我.

目前我的UISegmentedControl的文本颜色变化有问题;它需要在第一次加载时使用UIControlStateSelected进行更改.代码有效,但只是有条件的.当您在导航栏上使用分段控件访问页面,点击后退按钮,然后再次访问该页面时,它可以正常工作.我假设这里有继承问题.让我解释..

分段控件的位置位于导航栏的顶部.

包含SegmentedControl的VIEwController的继承:
TabbarVIEwController(使用AppDelegate管理) – >导航控制器 – > VIEwController(‘inviteSegbar’所在的位置)

这是AppDelegate.m中的代码:

[[UINavigationbar appearance] setbarTintcolor:[UIcolor colorWithHexString:@"#669900"]];//this one sets it green.[[UINavigationbar appearance] setBackgroundcolor:[UIcolor whitecolor]];

这里是vIEwDIDLoad:VC的代码,其中包含’inviteSegbar’,即所讨论的UISegmentedControl:

- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    //CUSTOM APPEaraNCE <below>    self.navigationController.navigationbar.barTintcolor = [UIcolor whitecolor];    self.navigationController.navigationbar.tintcolor = [UIcolor colorWithHexString:@"#669900"];    inviteSegbar.tintcolor = [UIcolor colorWithHexString:@"#333333"];    [[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundcolorAttributename : [UIcolor colorWithHexString:@"#669900"]} forState:UIControlStateSelected];}

就像我说的最后一行有效,但只有当你重新访问该页面时.为什么会这样?

PS这是同样的问题,我已经在列出任何答案之前尝试过此代码.

解决方法 答案:简单地移动
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundcolorAttributename : [UIcolor colorWithHexString:@"#669900"]} forState:UIControlStateSelected];

到您的AppDelegate.m文件

总结

以上是内存溢出为你收集整理的ios – UISegmentedControl仅在重新访问ViewController时更改文本颜色全部内容,希望文章能够帮你解决ios – UISegmentedControl仅在重新访问ViewController时更改文本颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1099004.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存