自定义NavigationBar

魏朗
2023-12-01

//

//  LLViewController.swift

//  LLNavigationBar

//

//  Created by 小白 on 2016/11/22.

//  Copyright © 2016 LinJian. All rights reserved.

//


import UIKit


class LLViewController: UIViewController {


    overridefunc viewDidLoad() {

        super.viewDidLoad()

        //设置视图颜色

        view.backgroundColor =UIColor.yellow

        //设置navigationBar的背景图片.以单位像素的图片填充背景.

        navigationController?.navigationBar.setBackgroundImage(UIImage(named:"navigationbar"), for:UIBarMetrics.default)

        //设置navigationItemtitle

        navigationItem.title ="Lucas"

        //设置title的字体以及颜色

        navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName :UIFont.systemFont(ofSize:20), NSForegroundColorAttributeName :UIColor.red]

    }


}

 类似资料: