Swift-Add a custom return button in the navigation bar and swift-navigation bar
// 1. Add the return button
Func addBackBtn (){
Let leftBtn: UIBarButtonItem = UIBarButtonItem (title: "back", style: UIBarButtonItemStyle. Plain, target: self, action: "actionBack ")
LeftBtn. title = "back ";
LeftBtn. tintColor = UICo
to the next page, the bar will automatically appear on the left side of the button, the text of the button is the default text content of the previous page Baritem, these are the default, will automatically help us build.Sometimes the problem is that if the "a" bar item's text content is very long, from a page push to B page, the text of the return button will be very long, so that the B page of the item content to squeeze to the right, this is very ugly.There are two ways we can handle this,1>
I. Create a project//slightly
Two. Create a View controller (shortcut: Do not go to create a swift file, just do the following
)
On the code (with comments) Appdelegate.swift
//
Appdelegate.swift
Swift Uinavigationcontroller Navigation Controller
//
Created by Zhangbiao on 14-6-16.
Copyright (c) 2014 ideals. All rights reserved.
//
Import UIKit
@UIApplication
Swift-teaches you how to implement UISearchController animation effects on navigation .,
This code snippet shows that I found various materials from the internet this week and modified it to get the upper and lower animation effects of the navigation:
Step 1: => because this search requires an animation effect, the page must have a
Swift sets the navigation bar to be transparent, that is, to set an empty picture, but if you only set this code, does not work, but also need other settings, directly on the code 1. Set navigation bar Title properties: Set title Color Self.navigationcontroller?. Navigationbar.titletextattributes = [NSForegroundColorAttributeName:UIColor.white]
This method is called when the class is first created, and is called only once by the overrideclass func Initialize () { = Uinavigationbar.appearance () // set the navigation bar to become opaque, so that the origin of the coordinates of the view starts from the bottom edge of the navigation bar, or you can set the background picture to achieve this effect . false
Create a single view appIn the View window stall a navigation controller, the default navigation controller is automatically associated with the table view, if not required, you can delete the automatically added table view, create a new view Controller can be associated with navigation controller. (Right-drag from Nav to view, select Rootview)650) this.width=650
Navigation bar and Tabbar combination of projects, in our usual development will often see, below we through the custom Tabbar to achieve a navigation and tabbar combination of demo.1. Custom TabbarImport UIKitclassgoftabbarcontroller:uitabbarcontroller{Overridefunc viewdidload () {super.viewdidload (); Addtabbarchildviewcontroller (Gofmainviewcontroller (), title:"Home Page", ImageName:"Tab_home", Selected
By default, the style of the navigation bar Uinavigationcontroller is simpler if you want to use code to modify the style.
1, modify the navigation bar background color
Modify the navigation bar background colorSelf.navigationcontroller? Navigationbar.bartintcolor =Uicolor (red:55/255, green:186/255, blue:89/255, alpha:1)
2, modify th
Using Navigationitem.leftbarbuttonitem and Navigationitem.rightbarbuttonitem makes it easy to set the left and right buttons for the navigation bar separately, but only one button on the side.
If you want to use multiple buttons on one side, you can do so by Leftbarbuttonitems and Rightbarbuttonitems.
Here's a demonstration of adding two buttons to the right of the navigation bar (search
Items often use Uinavigationcontroller to navigate the individual pages, the return button on the left-hand side of the navigation bar, the default title text is the parent page title.
However, if the title (title) text of the subpage is too long, the text of the return button disappears:
Similarly, modify the text of the return button even if you set Navigationitem.backbarbuttonitem as a custom Uibarbuttonitem in
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)) Tit
Navigationcontroller (navigation Controller) view with a sliding gesture, as long as the left side of the screen drag the page to the right, you can slide back to the previous page. But this feature only slides to the left edge of the screen to trigger, we can slightly change, let it support full-screen sliding back.
1, Full screen slide return realization principle
(1) The system takes the gesture is the Uiscreenedgepangesturerecognizer type obje
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.