給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)

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