git.iko.soy/dashared/GDproject
on master help sign in
added gradient and full post footer and header
27c8e84Darya Rednikina
GDproject.xcodeproj/project.pbxproj+13−1
@@ -27,6 +27,7 @@
27 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCB22144725006FCDD7 /* PostViewCell.swift */; };
27 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCB22144725006FCDD7 /* PostViewCell.swift */; };
28 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCD22144756006FCDD7 /* Constants.swift */; };
28 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCD22144756006FCDD7 /* Constants.swift */; };
29 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD022148122006FCDD7 /* FullPostController.swift */; };
29 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD022148122006FCDD7 /* FullPostController.swift */; };
30+ 12E36DD522156559006FCDD7 /* MyStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD422156559006FCDD7 /* MyStackView.swift */; };
30/* End PBXBuildFile section */
31/* End PBXBuildFile section */
31
32
32/* Begin PBXCopyFilesBuildPhase section */
33/* Begin PBXCopyFilesBuildPhase section */
@@ -66,6 +67,7 @@
66 12E36DCB22144725006FCDD7 /* PostViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewCell.swift; sourceTree = "<group>"; };
67 12E36DCB22144725006FCDD7 /* PostViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewCell.swift; sourceTree = "<group>"; };
67 12E36DCD22144756006FCDD7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
68 12E36DCD22144756006FCDD7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
68 12E36DD022148122006FCDD7 /* FullPostController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullPostController.swift; sourceTree = "<group>"; };
69 12E36DD022148122006FCDD7 /* FullPostController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullPostController.swift; sourceTree = "<group>"; };
70+ 12E36DD422156559006FCDD7 /* MyStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyStackView.swift; sourceTree = "<group>"; };
69/* End PBXFileReference section */
71/* End PBXFileReference section */
70
72
71/* Begin PBXFrameworksBuildPhase section */
73/* Begin PBXFrameworksBuildPhase section */
@@ -137,16 +139,25 @@
137 12E36DCF22145923006FCDD7 /* Controller */ = {
139 12E36DCF22145923006FCDD7 /* Controller */ = {
138 isa = PBXGroup;
140 isa = PBXGroup;
139 children = (
141 children = (
142+ 12E36DD422156559006FCDD7 /* MyStackView.swift */,
140 12E36DD022148122006FCDD7 /* FullPostController.swift */,
143 12E36DD022148122006FCDD7 /* FullPostController.swift */,
141 12E36DC522144266006FCDD7 /* HeaderNewsChannels.swift */,
144 12E36DC522144266006FCDD7 /* HeaderNewsChannels.swift */,
142 12E36DC722144374006FCDD7 /* ChannelsController.swift */,
145 12E36DC722144374006FCDD7 /* ChannelsController.swift */,
143 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
146 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
144− 12E36DCB22144725006FCDD7 /* PostViewCell.swift */,
147+ 12E36DD322156519006FCDD7 /* News */,
145 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
148 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
146 );
149 );
147 path = Controller;
150 path = Controller;
148 sourceTree = "<group>";
151 sourceTree = "<group>";
149 };
152 };
153+ 12E36DD322156519006FCDD7 /* News */ = {
154+ isa = PBXGroup;
155+ children = (
156+ 12E36DCB22144725006FCDD7 /* PostViewCell.swift */,
157+ );
158+ path = News;
159+ sourceTree = "<group>";
160+ };
150/* End PBXGroup section */
161/* End PBXGroup section */
151
162
152/* Begin PBXNativeTarget section */
163/* Begin PBXNativeTarget section */
@@ -219,6 +230,7 @@
219 isa = PBXSourcesBuildPhase;
230 isa = PBXSourcesBuildPhase;
220 buildActionMask = 2147483647;
231 buildActionMask = 2147483647;
221 files = (
232 files = (
233+ 12E36DD522156559006FCDD7 /* MyStackView.swift in Sources */,
222 12E36DC822144374006FCDD7 /* ChannelsController.swift in Sources */,
234 12E36DC822144374006FCDD7 /* ChannelsController.swift in Sources */,
223 12E36DB922144016006FCDD7 /* User.swift in Sources */,
235 12E36DB922144016006FCDD7 /* User.swift in Sources */,
224 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
236 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
GDproject/Controller/FullPostController.swift+70
@@ -7,6 +7,7 @@
7//
7//
8
8
9import UIKit
9import UIKit
10+import TinyConstraints
10
11
11class FullPostController: UITableViewController {
12class FullPostController: UITableViewController {
12
13
@@ -16,8 +17,22 @@ class FullPostController: UITableViewController {
16 super.viewDidLoad()
17 super.viewDidLoad()
17
18
18 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
19 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
20+
21+ setUpNavigationBar()
22+ tableView.separatorStyle = .none
19 }
23 }
20
24
25+ func setUpNavigationBar(){
26+ navigationController?.navigationBar.prefersLargeTitles = false
27+ navigationItem.title = "\(String(describing: post?.fromUser.login))"
28+ navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.options))]
29+ }
30+
31+ @objc func options(){
32+ // copy link
33+ // share
34+ //
35+ }
21 // MARK: - Table view data source
36 // MARK: - Table view data source
22
37
23 override func numberOfSections(in tableView: UITableView) -> Int {
38 override func numberOfSections(in tableView: UITableView) -> Int {
@@ -25,6 +40,59 @@ class FullPostController: UITableViewController {
25 return 2
40 return 2
26 }
41 }
27
42
43+ override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
44+ let view = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
45+ view.backgroundColor = .white
46+ switch section {
47+ case 0:
48+ return view
49+ default:
50+ return nil
51+ }
52+ }
53+
54+ override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
55+ {
56+ let view = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
57+
58+ let label = UILabel()
59+ label.font = UIFont.systemFont(ofSize: 14, weight: .regular)
60+ label.text = post?.comments.count == 0 ? "Add first relpy" : "\(post?.comments.count ?? 0) replies"
61+ label.textColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
62+
63+ let button = UIButton(type: .detailDisclosure)
64+
65+ view.backgroundColor = .white
66+ view.addSubview(button)
67+ view.addSubview(label)
68+
69+ label.edgesToSuperview(excluding: .right, insets: .left(16))
70+ button.edgesToSuperview(excluding: .left, insets: .right(16))
71+
72+ switch section {
73+ case 0:
74+ return view
75+ default:
76+ return nil
77+ }
78+ }
79+ override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
80+ switch section {
81+ case 0:
82+ return 50
83+ default:
84+ return 0
85+ }
86+ }
87+
88+ override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
89+ switch section {
90+ case 0:
91+ return 50
92+ default:
93+ return 0
94+ }
95+ }
28 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
96 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
29 {
97 {
30 switch section {
98 switch section {
@@ -44,6 +112,8 @@ class FullPostController: UITableViewController {
44 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
112 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
45
113
46 cell.fill(with: post!.dataArray, true)
114 cell.fill(with: post!.dataArray, true)
115+ cell.selectionStyle = .none
47 return cell
116 return cell
48 }
117 }
118+
49}
119}
GDproject/Controller/MyStackView.swiftnew file+27
@@ -0,0 +1,27 @@
1+//
2+// MyStackView.swift
3+// GDproject
4+//
5+// Created by cstore on 14/02/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class MyStackView: UIStackView {
12+
13+ var isFull: Bool = true
14+
15+
16+ override var bounds: CGRect {
17+ didSet{
18+ if frame.height == 300 && !isFull {
19+ let gradientLayer = CAGradientLayer()
20+ gradientLayer.colors = [UIColor(displayP3Red: 255, green: 255, blue: 255, alpha: 0).cgColor, UIColor.white.cgColor]
21+ gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.5)
22+ gradientLayer.frame = self.bounds
23+ self.layer.addSublayer(gradientLayer)
24+ }
25+ }
26+ }
27+}
GDproject/Controller/PostViewCell.swift → GDproject/Controller/News/PostViewCell.swiftrenamed+7−6
@@ -16,7 +16,7 @@ class PostViewCell: UITableViewCell
16 let nameLabel: UILabel = {
16 let nameLabel: UILabel = {
17 let label = UILabel()
17 let label = UILabel()
18 label.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
18 label.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
19− label.text = "vgogomazova"
19+ label.text = "vbogomazova"
20 label.font = UIFont.boldSystemFont(ofSize: 16)
20 label.font = UIFont.boldSystemFont(ofSize: 16)
21 return label
21 return label
22 }()
22 }()
@@ -84,16 +84,17 @@ class PostViewCell: UITableViewCell
84 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
84 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
85 nameStackView.axis = .vertical
85 nameStackView.axis = .vertical
86 contentView.addSubview(nameStackView)
86 contentView.addSubview(nameStackView)
87− nameStackView.height(46)
87+ //nameStackView.height(46)
88− nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(16) + .right(16))
88+ nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(20) + .right(20) + .top(8))
89
89
90− let stackView = UIStackView(arrangedSubviews: views)
90+ let stackView = MyStackView(arrangedSubviews: views)
91+ stackView.isFull = full
91 stackView.axis = .vertical
92 stackView.axis = .vertical
92 contentView.addSubview(stackView)
93 contentView.addSubview(stackView)
93 if !full {
94 if !full {
94 stackView.height(300, relation: .equalOrLess, isActive: true)
95 stackView.height(300, relation: .equalOrLess, isActive: true)
95 }
96 }
96− stackView.topToBottom(of: nameStackView)
97+ stackView.topToBottom(of: nameStackView, offset: 16, relation: .equal, isActive: true)
97− stackView.edgesToSuperview(excluding: .top, insets: .bottom(8) + .left(16) + .right(16))
98+ stackView.edgesToSuperview(excluding: .top, insets: .left(16) + .right(16))
98 }
99 }
99}
100}
GDproject/Controller/NewsController.swift+7−2
@@ -15,7 +15,7 @@ class NewsController: UIViewController
15
15
16 @IBOutlet weak var tableView: UITableView!
16 @IBOutlet weak var tableView: UITableView!
17
17
18− var dataSourse: [Post] = []
18+ var dataSourse: [Post] = [Post(dataArray: [.text("Le Lorem Ipsum est simplement du faux texte employé dans la composition et la mise en page avant impression. Le Lorem Ipsum est le faux texte standard de l'imprimerie depuis les années 1500, quand un imprimeur anonyme assembla ensemble des morceaux de texte pour réaliser un livre spécimen de polices de texte. Il n'a pas fait que survivre cinq siècles, mais s'est aussi adapté à la bureautique informatique, sans que son contenu n'en soit modifié. Il a été popularisé dans les années 1960 grâce à la vente de feuilles Letraset contenant des passages du Lorem Ipsum, et, plus récemment, par son inclusion dans des applications de mise en page de texte, comme Aldus PageMaker. \n On sait depuis longtemps que travailler avec du texte lisible et contenant du sens est source de distractions, et empêche de se concentrer sur la mise en page elle-même. L'avantage du Lorem Ipsum sur un texte générique comme 'Du texte. Du texte. Du texte.' est qu'il possède une distribution de lettres plus ou moins normale, et en tout cas comparable avec celle du français standard. De nombreuses suites logicielles de mise en page ou éditeurs de sites Web ont fait du Lorem Ipsum leur faux texte par défaut, et une recherche pour 'Lorem Ipsum' vous conduira vers de nombreux sites qui n'en sont encore qu'à leur phase de construction. Plusieurs versions sont apparues avec le temps, parfois par accident, souvent intentionnellement (histoire d'y rajouter de petits clins d'oeil, voire des phrases embarassantes).")], from: User(name: "vbogomazova1", id: 2, fullName: "Богомазова Вероника Львовна"), date: "14.02.19 в 12:05")]
19
19
20 override func viewDidLoad()
20 override func viewDidLoad()
21 {
21 {
@@ -34,6 +34,7 @@ class NewsController: UIViewController
34 super.viewWillAppear(animated)
34 super.viewWillAppear(animated)
35 navigationController?.navigationBar.prefersLargeTitles = true
35 navigationController?.navigationBar.prefersLargeTitles = true
36 }
36 }
37+
37 func setUpNavigationItemsforPosts(){
38 func setUpNavigationItemsforPosts(){
38 navigationItem.title = "Posts"
39 navigationItem.title = "Posts"
39 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:)))]
40 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:)))]
@@ -71,6 +72,8 @@ class NewsController: UIViewController
71extension NewsController: UITableViewDelegate{
72extension NewsController: UITableViewDelegate{
72 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
73 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
73 {
74 {
75+ tableView.deselectRow(at: indexPath, animated: true)
76+
74 let vc = storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
77 let vc = storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
75
78
76 vc.post = dataSourse[indexPath.row]
79 vc.post = dataSourse[indexPath.row]
@@ -85,10 +88,12 @@ extension NewsController: UITableViewDataSource
85 return dataSourse.count
88 return dataSourse.count
86 }
89 }
87
90
88− func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
91+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
92+ {
89 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
93 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
90
94
91 cell.fill(with: dataSourse[indexPath.row].dataArray, false)
95 cell.fill(with: dataSourse[indexPath.row].dataArray, false)
96+ cell.selectionStyle = .none
92 return cell
97 return cell
93 }
98 }
94
99