Swift set up navigation bar (Basic article)

Source: Internet
Author: User
Extension homeviewcontroller{private func Setupnavigationbar () {/*** set navigation bar background color ***/ Navigationcontroller?. Navigationbar.bartintcolor = uicolor.red/*** Set nav bar title ***///Self.title = "NetEase News "Navigationcontroller?"
        Navigationbar.titletextattributes = [NSAttributedStringKey.foregroundColor:UIColor.white]//Custom View settings title Let Titlelabel = UILabel (Frame:cgrect (x:0, y:0, width:40, height:40)) Titlelabel.text = "NetEase News" Ti Tlelabel.textcolor = Uicolor.white Navigationitem.titleview = titlelabel//Picture Let ImageView = UII
         Mageview (Image:uiimage (named: "Contentview_imagebg_logo")) Navigationitem.titleview = ImageView/*** Set the navigation bar left and Right buttons ***///text Let Leftbarbuttonitem = Uibarbuttonitem (title: "LeftButton", style:. pl Ain, target:self, Action: #selector (Self.leftclick)) Let Rightbarbuttonitem = UIBarbuttonitem (title: "Rightbutton", Style:. Plain, target:self, Action: #selector (Self.rightclick)) Navigationit
        Em.leftbarbuttonitem = Leftbarbuttonitem Navigationitem.rightbarbuttonitem = rightbarbuttonitem//Picture Navigationitem.leftbarbuttonitem = Uibarbuttonitem (Image:uiimage (named: "Fog"), style:. Plain, target:self, action: #selector (self.leftclick)) Navigationitem.rightbarbuttonitem = Uibarbuttonitem (Image:uiimage (named: "Fog"), style :. Plain, target:self, Action: #selector (Self.rightclick))//Custom Let LeftButton = UIButton (frame:cgrect
        (x:0, y:0, width:40, height:40)) Let Rightbutton = UIButton (Frame:cgrect (x:0, y:0, width:40, height:40)) Leftbutton.settitlecolor (Uicolor.blac K, For:UIControlState.normal) Rightbutton.settitlecolor (Uicolor.black, For:UIControlState.normal) LEFTBU Tton.settitle ("LeftButton", For:UIControlState.normal) rightbutton.settitle ("Rightbutton", FOr:UIControlState.normal) Leftbutton.addtarget (Self, Action: #selector (Leftclick), for:UIControlEvents.touchUpIn side) Rightbutton.addtarget (Self, Action: #selector (RightClick), for:UIControlEvents.touchUpInside) Navig Ationitem.leftbarbuttonitem = Uibarbuttonitem (customview:leftbutton) Navigationitem.rightbarbuttonitem = UIBarBut

    Tonitem (Customview:rightbutton)//Barbuttonitem Color leftbarbuttonitem.tintcolor = uicolor.black} @objc private func Leftclick () {print ("Leftclick")} @objc private Func RightClick () {print (" RightClick ")}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.