UINavigationController with custom shape navigation Bar

前端 未结 2 1772
孤街浪徒
孤街浪徒 2021-01-06 06:19

I\'m trying to create a custom UINavigationBar with a custom shape, like this (ignore transparency)

\"enter

2条回答
  •  广开言路
    2021-01-06 07:01

    Well, I'm silly xD

    Finally I got a solution for this issue and it was much simpler than I expected.

    Here are the steps:

    1) Subclass UINavigationBar, I created a CustomNavigationBar object.

    2) Inside it's init, write this lines

    UIImage *image = [UIImage imageNamed:@"barBackgroundImageName"];
    [self setBackgroundImage:image forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
    [self setShadowImage:[UIImage new]];
    

    This is important and the reason why I couldn't make all this thing work, image's height must be 64px. I find out this on the online Apple Documentation where it describes the behaviour between UINavigationBar and the Status Bar.

    3) And that's all. This is the result in my case (I know the background isn't symmetric, just a test).

    enter image description here

    Thanks to all for your time and help!!!

提交回复
热议问题