给navigationbar设置背景图片,并且按比例延伸,显示完整图片

oc :

//按比例显示图片 
UIImage *backGroundImage = [UIImage imageNamed:@”NavigationBar”]; 
backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch]; 
[self.navigationController.navigationBar setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];

swift:

var image = UIImage()

        image = UIImage.init(named: "NavigationBar")!

        //这句话按照比例延伸,显示完整图片

        image = image.resizableImage(withCapInsets: UIEdgeInsets.zero, resizingMode: UIImage.ResizingMode.stretch)

        navigationBar.setBackgroundImage(image, for: .default)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章