using image or tint color on uinavigationbar in iphone?

前端 未结 7 1753
自闭症患者
自闭症患者 2020-12-24 09:58

how do i show a background image on a navigation bar or give tint color to the navigation bar in a native iphone application??

7条回答
  •  一生所求
    2020-12-24 10:27

    If you use the CGImage solution, you may have a problem with image size:

    CGRect layer=self.navigationController.navigationBar.frame;
    layer.size.height=57.0;
    layer.origin.y=0;
    self.navigationController.navigationBar.frame=layer;
    CGImageRef imageRef         = [UIImage imageNamed:@"myImg.png"].CGImage;
    self.navigationController.navigationBar.layer.contents = (id)imageRef;
    

    It seems to me that the image is streched down, since the layer seems to have a height of 44.0 pixel, but a background image for the UINavigationBar should be at least 57.0.

    If you try to move the layer's frame, all the buttons will move within it.

提交回复
热议问题