-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PROGRESS child view controllers, GFUserInfoHeaderVC
- Loading branch information
grenos
committed
Mar 31, 2020
1 parent
7254b2a
commit f4b66bd
Showing
6 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+6.01 KB
(110%)
...odeproj/project.xcworkspace/xcuserdata/vasilis.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
39 changes: 39 additions & 0 deletions
39
GHFollowers/Components/Labels/GFTitleLabel-Secondary.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// GFTitleLabel-Secondary.swift | ||
// GHFollowers | ||
// | ||
// Created by Vasileios Gkreen on 31/03/2020. | ||
// Copyright © 2020 Vasileios Gkreen. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class GFTitleLabel_Secondary: UILabel { | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
configure() | ||
} | ||
|
||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
|
||
init(fontSize: CGFloat) { | ||
super.init(frame: .zero) | ||
font = UIFont.systemFont(ofSize: fontSize, weight: .medium) | ||
|
||
configure() | ||
} | ||
|
||
|
||
private func configure () { | ||
textColor = .secondaryLabel | ||
adjustsFontSizeToFitWidth = true | ||
minimumScaleFactor = 0.90 | ||
lineBreakMode = .byTruncatingTail | ||
translatesAutoresizingMaskIntoConstraints = false | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
GHFollowers/Components/ViewControllers/GFUserInfoheaderVC.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// GFUserInfoheaderVC.swift | ||
// GHFollowers | ||
// | ||
// Created by Vasileios Gkreen on 01/04/2020. | ||
// Copyright © 2020 Vasileios Gkreen. All rights reserved. | ||
// | ||
|
||
|
||
import UIKit | ||
|
||
class GFUserInfoheaderVC: UIViewController { | ||
|
||
let avatarImageView = GFAvatarImageView(frame: .zero) | ||
let usernameLabel = GFTitleLabel(textAlignment: .left, fontSize: 34) | ||
let nameLabel = GFTitleLabel_Secondary(fontSize: 18) | ||
let locationImageView = UIImageView() | ||
let locationLabel = GFTitleLabel_Secondary(fontSize: 18) | ||
let bioLabel = GFBodyLabel(textAlignment: .left) | ||
|
||
var user: User! | ||
|
||
// create a custom initializer | ||
// so when we initialize the VC we can pass the User object | ||
init(user: User) { | ||
super.init(nibName: nil, bundle: nil) | ||
self.user = user | ||
} | ||
// the no storyboard init | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
addSubViews() | ||
layoutUI() | ||
configureUIElements() | ||
} | ||
|
||
|
||
func configureUIElements() { | ||
avatarImageView.downloadImage(from: user.avatarUrl) | ||
usernameLabel.text = user.login | ||
nameLabel.text = user.name ?? "" // nil coalescing (if null then use placeholder in string) | ||
locationLabel.text = user.location ?? "No Location" | ||
bioLabel.text = user.bio ?? "" | ||
bioLabel.numberOfLines = 3 | ||
|
||
locationImageView.image = UIImage(systemName: SFSymbols.location) | ||
// ovveride the default blue color of SFSymbols | ||
locationImageView.tintColor = .secondaryLabel | ||
} | ||
|
||
|
||
|
||
// MARK: VIEW FUNCTIONS | ||
|
||
// add all the subView here | ||
func addSubViews() { | ||
view.addSubview(avatarImageView) | ||
view.addSubview(usernameLabel) | ||
view.addSubview(nameLabel) | ||
view.addSubview(locationImageView) | ||
view.addSubview(locationLabel) | ||
view.addSubview(bioLabel) | ||
} | ||
|
||
|
||
// add all constraints for the elements here | ||
func layoutUI() { | ||
let padding: CGFloat = 20 | ||
let textImagePadding: CGFloat = 12 | ||
locationImageView.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
NSLayoutConstraint.activate([ | ||
avatarImageView.topAnchor.constraint(equalTo: view.topAnchor, constant: padding), | ||
avatarImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: padding), | ||
avatarImageView.widthAnchor.constraint(equalToConstant: 90), | ||
avatarImageView.heightAnchor.constraint(equalToConstant: 90), | ||
|
||
usernameLabel.topAnchor.constraint(equalTo: avatarImageView.topAnchor), | ||
usernameLabel.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: textImagePadding), | ||
usernameLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -padding), | ||
usernameLabel.heightAnchor.constraint(equalToConstant: 38), | ||
|
||
nameLabel.centerYAnchor.constraint(equalTo: avatarImageView.centerYAnchor, constant: 8), | ||
nameLabel.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: textImagePadding), | ||
nameLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -padding), | ||
nameLabel.heightAnchor.constraint(equalToConstant: 20), | ||
|
||
locationImageView.bottomAnchor.constraint(equalTo: avatarImageView.bottomAnchor), | ||
locationImageView.leadingAnchor.constraint(equalTo: avatarImageView.trailingAnchor, constant: textImagePadding), | ||
locationImageView.heightAnchor.constraint(equalToConstant: 20), | ||
locationImageView.widthAnchor.constraint(equalToConstant: 20), | ||
|
||
locationLabel.centerYAnchor.constraint(equalTo: locationImageView.centerYAnchor), | ||
locationLabel.leadingAnchor.constraint(equalTo: locationImageView.trailingAnchor, constant: 5), | ||
locationLabel.trailingAnchor.constraint(equalToSystemSpacingAfter: view.trailingAnchor, multiplier: -padding), | ||
locationLabel.heightAnchor.constraint(equalToConstant: 20), | ||
|
||
bioLabel.topAnchor.constraint(equalTo: avatarImageView.bottomAnchor, constant: textImagePadding), | ||
bioLabel.leadingAnchor.constraint(equalTo: avatarImageView.leadingAnchor), | ||
bioLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -padding), | ||
bioLabel.heightAnchor.constraint(equalToConstant: 60) | ||
]) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Constants.swift | ||
// GHFollowers | ||
// | ||
// Created by Vasileios Gkreen on 01/04/2020. | ||
// Copyright © 2020 Vasileios Gkreen. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum SFSymbols { | ||
static let location = "mappin.and.ellipse" | ||
} |