Create navigation bar with title and subtitle

Solution:


You can easily set the title and subtitle using the below method.Just call the below method to set the subtitle to the navigationBar.

    func setsubTitle(titleStr: String, subStr: String,viewControl:UIViewController) {

        let rect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50)

        let titleSize: CGFloat = 20

        let subtitleSize: CGFloat = 15


        let titleLabel = UILabel(frame: rect)

        titleLabel.backgroundColor = .clear

        titleLabel.numberOfLines = 2

        titleLabel.textColor = .white


        let text = NSMutableAttributedString()

        text.append(NSAttributedString(string: titleStr, attributes: [.font : UIFont.boldSystemFont(ofSize: titleSize)]))

        text.append(NSAttributedString(string: "\n\(subStr)", attributes: [.font : UIFont.systemFont(ofSize: subtitleSize)]))

        titleLabel.attributedText = text

        viewControl.navigationItem.titleView = titleLabel

    }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift