Custom Navigation Bar: Swift 4.2 Skip to main content

Custom Navigation Bar: Swift 4.2

Overview

Hello iOS Developer, we all want our custom module which helps us dynamically and in easy of implementing with our purpose. Here image, show what we going to learn in this tutorial.

Custom Navigation Bar: Swift 4.2
Custom Navigation Bar: Swift 4.2
As you can see over here there are two labels and one image view with the image of the drop-down arrow. Here two labels are stack in the vertical stack view and image view and vertical stack view will be stack in horizontal stack view. At last, we are going to add a target to handle tap event on title view.

I'm assuming that you are familiar with project setup. Open Storyboard, an embed navigation controller to view controller. Create a new swift named it "NavigationTitleViewDropdown". Now here we are going to create a class with the same name as a swift file, a superclass will be UIButton because we required tap event handling.

Now we are going to create some variables. First one is label title a compute variable here we are going to change some property values as per our need.
The translatesAutoresizingMaskIntoConstraints we need to make false because further, we are going to give runtime constraints and going to change some property too.

Thus the same goes for label subtitle with some minor modification.
Those both variable are to going to subviews in vertical stack view, so now creating vertical stack view. In here make sure "isUserInteractionEnabled" should be false, by default is stated as true and some minor property modification.
Creating a new extension of this class. This extension use for UI Related Methods. Here we going to create a method call prepare UIView.
This method will be going to call from override init method below the super init initialize with a frame.
Therefore we need to add two above label as subviews in vertical stack-view and adding vertical stack-view in a class subview and giving constraint according to it.

For adding subviews we are going to create the method of it. In this gone add all subview.
Same goes for the constraint related, creating a new method of it and giving center, height and width constraint runtime to vertical stack-view.
Thus call both methods in preparing UIView.
After that creating configuration method which will set title and subtitle.
Now jump to the ViewController class. Create a variable of NavigationTitleViewDropdown with initialization.
Therefore we need to prepare a navigation bar, going to create a separate method for it. In this adding target method where we can handle tap event of navigation bar title view. For this tutorial purpose, I'm going to print just "Navigation bar title view pressed". Configuring the title and sub-title and adding our custom navigation title-view to navigation item title-view.

Run the application, go and press title-view. It will print statement in the console. Only a couple of thing is left to do over here. Adding drop-down arrow image and high-lighting title-view.

For adding the image drop-down we need to create a variable of it.
This variable will be going to adding into horizontal stack-view.

Before running the application we need to add vertical stack-view and image-view into horizontal stack-view, also adding horizontal stack-view into class sub-view.
At last just the constraint to horizontal stack-view from vertical stack-view.

Run the application, we added image drop-down successfully also we with handling the tap event of title-view. Full Code with highlighting navigation bar tap.

Full Video:


Feel free to comment and sharing.

Comments

  1. Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is fantastic, let alone the content!

    3D Animation Services in Atlanta
    Chatbot Development Company
    Mobile app development in Coimbatore

    ReplyDelete
  2. Now year has been completed, If you like content, Please share and let me know. So, it will be motivate to post more content like this. Thanks

    ReplyDelete
  3. Nice Blog.
    I had a look at your blog in detail and seems that it is very useful for all the users who are looking to understand about Custom Navigation Bar with Swift. I was looking for swift application development company

    ReplyDelete
  4. ​Please accept our apologies for the unintended delay.

    Which need to be recorrect by owner.
    --> Feel free to share your suggestions.

    Thanks

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hotel and Casino: Atlantic City, NJ - Mapyro
    Mapyro Resort and Casino 정읍 출장샵 offers 5500 rooms and 평택 출장마사지 suites. 경기도 출장마사지 Featuring 1,500 rooms and suites, this 원주 출장안마 hotel is located in Atlantic City, NJ. Rating: 4.5 · ‎8 나주 출장샵 reviews

    ReplyDelete

Post a Comment

Popular posts from this blog

Security Code AutoFill(One Time Password): Swift 4.2

Overview Hello Everyone, Hope you doing well and having a fantastic day. Apple introduces one cool new feature in iOS 12 is OTP ( One Time Password ) a security code autofill. This article teaches how to implement security code autofill in the easiest way. Storyboard: Go ahead drag UITextField on ViewController . Security Code AutoFill(One Time Password): Swift 4.2 Click on textField and open attribute inspector in that change content type to One Time Code . Security Code AutoFill(One Time Password): Swift 4.2 That's it, we have successfully implemented  One Time Code verification functionality to our application. Just run the application in your device. Here is Result Security Code AutoFill(One Time Password): Swift 4.2 Note: Security code autoFill will work only with the native keyword. Feel free to share and comment.

Local Authentication: Swift 4.2

Local Authentication: Swift 4.2 Hello Everyone, This article will be going to teach about Local Authentication. How to use, implement with using a custom struct. Hope you will like it. A quick demonstrate regarding what we going to learn in this tutorial. As you can see, a single authenticate button when I pressed, it presents Authentication alert which allows us to scan our biometric with reason message why we want to use user biometric. If user authentication is successfully completed then I have shown an alert popup with a successfully authenticated message. If the user biometric unable to recognize, so we can use passcode fallback functionality for the authentication. I'm assuming that you are familiar with project setup. Open Storyboard, Drag an UIButton named it as Authenticate. Jump to ViewController Class create an IBOutlet for Authenticate button and IBAction for it. That's it for design related stuff. Create a new swift file and named it properly, mine