HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UISegmentedControl仅在重新访问ViewController时更改文本颜色大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
更新回答.由我.

目前我的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时更改文本颜色所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。