iOS 4 上的 UIToolbar 色调
刚刚在我的 iPhone 3GS 上切换到 iOS 4,我的一些应用程序崩溃了。
我遇到的一个问题是,我有一个带有一些按钮的 UIToolbar,颜色为粉红色,在 3.1.3 操作系统上运行良好。升级到 iOS 4 后,工具栏仍然有颜色,但其中包含的按钮不再受颜色影响。工具栏是粉红色的,而按钮是普通蓝色的。
在网上查了一下,没有发现这样的事情。
有谁知道这个过程中发生了什么?
just switched to iOS 4 on my iPhone 3GS and some of my apps broke.
One issue I had is that I had a UIToolbar with some buttons, tinted to pink, that worked well on the 3.1.3 OS. After upgrading to iOS 4, the toolbar was still tinted, but the buttons it contained were no longer affected by the tint. The toolbar was pink while the buttons were regular-blue.
Looked around for it on the net, but found no reference of such a thing.
Anyone knows what broke in the process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(这里必须坦白 - 我在发布之前就知道答案,只是不知道如何将这些数据加载到 StackOverflow。认为我找到的解决方案对其他人很有价值,所以想在这里发布。我是新来的,所以请不要严厉批评:))
因此,最终问题是由于操作系统行为的变化(AFAICT)造成的。
如前所述,色调代码在升级之前有效,并且是这样编写的:
我需要做的只是颠倒事情的顺序:(
如果您在 Interface Builder 中创建了 UIToolbar,您可以在那里更改它的色调,这适用于按钮也是如此)。
我猜想在 iOS 4 之前,色调会更新所有按钮,而在 iOS 4 中则不会,并且在添加按钮时,它们会检查现有色调。但这只是一个猜测。无论如何,该解决方案有效......
希望这对某人有帮助,并且我没有违反任何神圣的规则......
干杯!
(must be frank here - I knew the answer before posting, just didn't know how to load this data to StackOverflow. Thought the solution I found was valuable for others, so wanted to post it here. I'm new here, so please no harsh critics :) )
So eventually the problem resulted from, AFAICT, a change in behavior in the OS.
As stated the tint code worked before the upgrade and was written like this:
What I needed to do, was just reverse the order of things:
(If you created UIToolbar in Interface Builder, you can change it's tint there, and that applies for the buttons as well).
I guess the tint updated all buttons before iOS 4, while in iOS 4 it doesn't and when adding buttons, they check for existing tint. But this is just a guess. The solution works anyhow..
Hope this helps someone, and that I didn't violate any sacred SO rules...
Cheers!
好吧,它看起来更像是一个操作系统错误,而不是一个功能,因为当您设置导航栏的色调颜色时,导航栏确实会更改其项目的颜色。
我们发现,如果您更改项目的样式,则会产生副作用,即刷新其颜色。在我们的案例中执行以下操作是有效的。原来的按钮是有边框的,所以我们把它们改为普通按钮,然后再次将它们设置为有边框。您可以执行更复杂和更通用的代码来保存当前样式,设置另一种样式,然后切换回来。我只是懒得这么做。 :D 无论如何,你明白了。
问候,
鲁拉。
Well, it seems more like an OS bug than a feature, since navigation bars do change their item's color when you set their tintColor.
We've found that if you change the item's style, it refreshes their color as a side effect. Doing the following worked in our case. The original buttons are bordered, so we change them to plain and set them to bordered again. You may do a more complicated and generic code that saves the current style, sets another one and then switchs back. I am just to lazy to do that. :D Anyway, you get the idea.
Regards,
Rula.