Premium Login UI/UX Design using Swift 4 Programmatically With Autolayouts - Swift 4 Tutorials W3Schools

Hot

Post Top Ad

23 Oct 2017

Premium Login UI/UX Design using Swift 4 Programmatically With Autolayouts

Now a days mobile apps are using premium UI/UX designs. Login screen UI/UX design itself says how the app is gonna look further.

In this article we are going to create following login screen. We are not gonna use storyboard.

The whole screen developed programmatically using swift 4.

Premium Login UI/UX Design using Swift 4 Programmatically

You can download the whole code in the bottom of this article.

Getting Started:

Here we created new Xcode project and rename  ViewController.swift name to LoginVC.swift and changed the subclass in storyboard.

First we need create all required sub views. In the above picture we are having different sub views. So we create as follow:

let bgImageView : UIImageView = {
    let imageView = UIImageView()
    imageView.translatesAutoresizingMaskIntoConstraints = false
    imageView.image = UIImage(named: "bg.jpg")
    imageView.contentMode = .scaleAspectFill
    return imageView
}()

let logoImageView : UIImageView = {
    let imageView = UIImageView()
    imageView.translatesAutoresizingMaskIntoConstraints = false
    imageView.alpha = 0.8
    imageView.image = UIImage(named: "skull.png")
    imageView.contentMode = .scaleAspectFit
    return imageView
}()

// ............

Like above we created all subviews. Download & see the completed project for creating remaining subviews.

Next we are adding all created subviews to the main view. For that we created addingUIElements() method as follow:

func addingUIElements() {
    let padding: CGFloat = 40.0
    let signInButtonHeight: CGFloat = 50.0
    let textFieldViewHeight: CGFloat = 60.0
    
    // Background imageview
    self.view.addSubview(bgImageView)
    bgImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0).isActive = true
    bgImageView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0).isActive = true
    bgImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0).isActive = true
    bgImageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0).isActive = true
    
    // Background layer view
    view.insertSubview(bgView, aboveSubview: bgImageView)
    bgView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0.0).isActive = true
    bgView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0.0).isActive = true
    bgView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0.0).isActive = true
    bgView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0.0).isActive = true
    
    // Logo at top
    view.insertSubview(logoImageView, aboveSubview: bgView)
    logoImageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 60.0).isActive = true
    logoImageView.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: 0.0).isActive = true
    logoImageView.heightAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.4).isActive = true
    logoImageView.widthAnchor.constraint(equalTo: logoImageView.heightAnchor, constant: 0.0).isActive = true

    //.......

} 

In the above code we added three views as subview to main view. For more download project in the bottom of this article.

Here we created new class named TextFieldView subview of UIView. This view is for the textField,mailLogo and Line. So that we can reuse for multiple TextFields.

textField,mailLogo and Line

This example we shown here doesn't have any functionality yet, it's only design created programmatically.

Download sample project with examples :

7 comments:

  1. Hi there! Nice stuff, do keep me posted when you post again something like this! therap login

    ReplyDelete
  2. Thankyou for this wondrous post, I am glad I observed this website on yahoo. 토토커뮤니티

    ReplyDelete
  3. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. 대전1인샵

    ReplyDelete
  4. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. 먹튀검증

    ReplyDelete
  5. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!! 먹튀검증

    ReplyDelete
  6. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. ui ux design agency

    ReplyDelete
  7. I'm a creative Website UI/UX Designer with more than 5 years of experience. During my career, I'd created dozens of different website UI designs and Admin panel UI designs. Create branding and web UI, Dashboards for growing businesses, building brands.

    ReplyDelete

Post Top Ad