相关疑难解决方法(0)

UIBarButtonItem在按下后更改字体,在外观代理中指定

我在AppDelegate中UIBarButtonItem通过appearance代理设置标题字体:

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                      [UIFont fontWithName:@"Segoe Print" size: 14.0], UITextAttributeFont,
                                                      DEF_TITLE_COLOR,UITextAttributeTextColor,
                                                      [UIColor colorWithRed:100/255 green:128/255 blue:43/255 alpha:0.4], UITextAttributeTextShadowColor,
                                                      [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil]
                                            forState:UIControlStateNormal&UIControlStateHighlighted&UIControlStateDisabled];
Run Code Online (Sandbox Code Playgroud)

之后我presentViewController::在我的应用程序的某个地方打电话.条形按钮显示正确的字体和背景图像,我在此ViewController中设置(不通过外观):

在此输入图像描述

但是当我按下"加入"按钮时,会显示标准的非自定义UIAlertView,并且在它出现在屏幕上之后我的barButton字体变为...标准?颜色也看起来像色彩.我不知道我做错了什么,尝试了很多东西来解决它:

在此输入图像描述

此错误仅出现在iOS7上.

xcode uibarbuttonitem ios ios7

5
推荐指数
1
解决办法
1166
查看次数

UIBarButtonItem色彩不起作用

我最近注意到,tintColor在最近的iOS 10更新中,该属性的行为发生了显着变化.

我有一个以前完美运行的代码,现在根本不工作.

在我的一个应用程序中,我有一组UIBarButtonItems被添加到toolbarItems视图控制器的数组中.它们显示得很好.

但是,在某些时候,我想要更改某些项目的色调颜色以响应用户操作.代码很简单:

flagButton.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)

这个代码以前用过,但现在它不起作用!我已经验证了对UIBarButtonItemexists 的引用以及执行这行代码.但是,色调颜色没有改变.

tintColor财产的描述中,它说:

要在此属性更改时刷新子视图呈现,请覆盖tintColorDidChange()方法.

我尝试添加tintColorDidChange方法,但没有调用.我在这个阶段的假设是,一旦tintColor更改,我的按钮不会自动刷新.

有人可以帮忙找到手动刷新它的方法吗?该按钮是UIBarButtonItem带图像的标准.

更新1

实际上我注意到,如果我更改tintColor工具栏而不是单个项目代码正在运行.似乎由于某种原因,在单个项目上设置色调颜色不再有效.有谁知道为什么会这样?

更新2

由于matt的提示,我能够找到问题的根源.它是由启动应用程序时执行的代码引起的:

[[UITableViewCell appearance] setTintColor:[ColourTheme sharedTheme].navBackground];
Run Code Online (Sandbox Code Playgroud)

现在,我完全不知道为什么这条线会引起UIBarButtonItem色彩问题...这可能是因为它引入了一些含糊之处UIAppearance.无论如何,由于我自己不再需要这条线,我可以轻松地将其移除.我仍然会打开我的问题,因为我认为这种行为非常奇怪,所以在某种程度上,这个问题仍然没有答案.

就像一个额外的信息 - 遇到这些问题的视图控制器包含一个表视图.

cocoa-touch uibarbuttonitem tintcolor ios ios10

5
推荐指数
1
解决办法
3237
查看次数

标签 统计

ios ×2

uibarbuttonitem ×2

cocoa-touch ×1

ios10 ×1

ios7 ×1

tintcolor ×1

xcode ×1