Here's one way:
[[theNavigationBar.subviews objectAtIndex:1] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[[theNavigationBar.subviews objectAtIndex:2] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
However, HUGE, caveat. This is highly likely to break on a future OS release and is not recommended.
At the very least you should perform a lot of testing and make sure you your assumptions of the subview layout of the navigation bar are correct.
或者
for (id subView in theNavigationBar.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
[(UIButton *)subView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[(UIButton *)subView setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
}
}
附:某个UINavigationBar的subviews:
Printing description of what:
(
"<UINavigationItemView: 0x66c18d0; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x66c1970>>",
"<UINavigationButton: 0x66c2490; frame = (7 7; 48 30); opaque = NO; layer = <CALayer: 0x66c2540>>",
"<UINavigationButton: 0x66c19d0; frame = (713 7; 48 30); opaque = NO; layer = <CALayer: 0x66c1920>>"
)