How to remove the black line below Uinavigationbar in iOS7

Source: Internet
Author: User

A way to get rid of a black line below the navigation bar during the project

Default Uinavigationbar Style

Prepare the background for replacement

The effect after replacement

if ([Self.navigationController.navigationBar respondstoselector: @selector (setbackgroundimage:forbarmetrics:)]) {

[Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ "TOP_BG"] forbarmetrics: Uibarmetricsdefault];

}

In iOS7, after executing the above code to replace the background image of Navigationbar, a very obvious black line appears, how do you remove the black lines?



-----------------------------------------------------------------------------------

Wait for one hours no one answer, good sad!

Fortunately, I solved it myself!

Here's how:

if ([Self.navigationController.navigationBar respondstoselector: @selector (setbackgroundimage:forbarmetrics:)]) {

Nsarray *list=self.navigationcontroller.navigationbar.subviews;

for (the ID obj in list) {

if ([obj Iskindofclass:[uiimageview class]]) {

Uiimageview *imageview= (Uiimageview *) obj;

Imageview.hidden=yes;

}

}

Uiimageview *imageview=[[uiimageview alloc] Initwithframe:cgrectmake (0,-20, 420, 64)];

Imageview.image=[uiimage imagenamed:@ "TOP_BG"];

[Self.navigationController.navigationBar Addsubview:imageview];

[Self.navigationController.navigationBar Sendsubviewtoback:imageview];

}

Final effect:

How to remove the black line below Uinavigationbar in iOS7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.