Skip to content

Commit

Permalink
itemInfoView
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 4, 2020
1 parent a007ac0 commit f8ea07b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
4 changes: 4 additions & 0 deletions GHFollowers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
7D7C665224388F0900733687 /* GFItemInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D7C665124388F0900733687 /* GFItemInfoView.swift */; };
7D98BB282428FE73006C53E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D98BB272428FE73006C53E9 /* AppDelegate.swift */; };
7D98BB2A2428FE73006C53E9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D98BB292428FE73006C53E9 /* SceneDelegate.swift */; };
7D98BB312428FE75006C53E9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D98BB302428FE75006C53E9 /* Assets.xcassets */; };
Expand Down Expand Up @@ -36,6 +37,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7D7C665124388F0900733687 /* GFItemInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFItemInfoView.swift; sourceTree = "<group>"; };
7D98BB242428FE73006C53E9 /* GHFollowers.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GHFollowers.app; sourceTree = BUILT_PRODUCTS_DIR; };
7D98BB272428FE73006C53E9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7D98BB292428FE73006C53E9 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,6 +194,7 @@
children = (
7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */,
7DA45F79242FB95700AB426F /* GFEmptyStateView.swift */,
7D7C665124388F0900733687 /* GFItemInfoView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -331,6 +334,7 @@
7DA45F69242B831900AB426F /* NetworkManager.swift in Sources */,
7D98BB282428FE73006C53E9 /* AppDelegate.swift in Sources */,
7DA45F852433FAF800AB426F /* GFUserInfoheaderVC.swift in Sources */,
7D7C665224388F0900733687 /* GFItemInfoView.swift in Sources */,
7D98BB2A2428FE73006C53E9 /* SceneDelegate.swift in Sources */,
7DA45F832433F4FC00AB426F /* Constants.swift in Sources */,
);
Expand Down
Binary file not shown.
87 changes: 87 additions & 0 deletions GHFollowers/Components/Views/GFItemInfoView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// GFItemInfoView.swift
// GHFollowers
//
// Created by Vasileios Gkreen on 04/04/2020.
// Copyright © 2020 Vasileios Gkreen. All rights reserved.
//

import UIKit

enum itemInfoType {
case repos, gists, following, followers
}


class GFItemInfoView: UIView {

let symbolImageView = UIImageView()
let titleLabel = GFTitleLabel(textAlignment: .left, fontSize: 14)
let countLabel = GFTitleLabel(textAlignment: .center, fontSize: 14)

override init(frame: CGRect) {
super.init(frame: frame)
configure()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}



private func configure() {
addSubview(symbolImageView)
addSubview(titleLabel)
addSubview(countLabel)

// ui setup for symbol
symbolImageView.translatesAutoresizingMaskIntoConstraints = false
symbolImageView.contentMode = .scaleAspectFill
symbolImageView.tintColor = .label


NSLayoutConstraint.activate([
// position symbol at top-left of view
symbolImageView.topAnchor.constraint(equalTo: self.topAnchor),
symbolImageView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
symbolImageView.heightAnchor.constraint(equalToConstant: 20),
symbolImageView.widthAnchor.constraint(equalToConstant: 20),

// center title label to the center of the symbol
titleLabel.centerYAnchor.constraint(equalTo: symbolImageView.centerYAnchor),
titleLabel.leadingAnchor.constraint(equalTo: symbolImageView.trailingAnchor, constant: 12),
titleLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor),
titleLabel.heightAnchor.constraint(equalToConstant: 18),

// pin top of counter at bottom of symbol
countLabel.topAnchor.constraint(equalTo: symbolImageView.bottomAnchor, constant: 4),
countLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor),
countLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor),
countLabel.heightAnchor.constraint(equalToConstant: 18)
])
}


func set(itemInfoType: itemInfoType, withCount count: Int ) {

switch itemInfoType {
case .repos:
symbolImageView.image = UIImage(systemName: SFSymbols.repos)
titleLabel.text = "Public Repos"
case .gists:
symbolImageView.image = UIImage(systemName: SFSymbols.gists)
titleLabel.text = "Public Gists"
case .followers:
symbolImageView.image = UIImage(systemName: SFSymbols.followers)
titleLabel.text = "Followers"
case .following:
symbolImageView.image = UIImage(systemName: SFSymbols.following)
titleLabel.text = "Following"
}

countLabel.text = String(count)
}


}
4 changes: 4 additions & 0 deletions GHFollowers/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ import Foundation

enum SFSymbols {
static let location = "mappin.and.ellipse"
static let repos = "folder"
static let gists = "text.alignleft"
static let followers = "heart"
static let following = "person.2"
}

0 comments on commit f8ea07b

Please sign in to comment.