zhangciwu
zhangciwu

Reputation: 351

How to modify the color of hairline of uinavigationbar

I've known the way to get the hairline view, which is a UIImageView, from this question:How to hide iOS7 UINavigationBar 1px bottom line

but, to modify this view's background color is so bad experience, code like this:

    [[self findHairlineImageViewUnder:self.navigationController.navigationBar] setBackgroundColor:[UIColor colorWithHexString:@"ff0000"]];

the findHairlineImageViewUnder method is from the answer link above

this works, but not always, even put in viewdidload,viewwillapear,viewDidLayoutSubviews, it will go back to original color at some scene, like after push and pop.

so, I'd like to ask if there is some perfect way to change the color of hairline of uinavigationbar, thanks.

Upvotes: 2

Views: 635

Answers (1)

zhangciwu
zhangciwu

Reputation: 351

now I found addd a subview to the hairline's superview did the trick and works fine

    UIView* sv= [[UIView alloc] initWithFrame:[self findHairlineImageViewUnder:self.navigationController.navigationBar].frame];
sv.backgroundColor=[UIColor colorWithHexString:@"ff0000"];
[[self findHairlineImageViewUnder:self.navigationController.navigationBar].superview addSubview:sv];

Upvotes: 1

Related Questions