git.iko.soy/dashared/GDproject
on master help sign in
added gradient and full post footer and header
commit27c8e84ff12ff9a2b62646fafaba85ba019fe34c authorDarya Rednikina <rednikina.com@yandex.ru> dateThu 14 Feb 2019, 15:07 (8 years ago) parent973f0ed
5 files changed+124−9
GDproject.xcodeproj/project.pbxproj+13−1 GDproject/Controller/FullPostController.swift+70 GDproject/Controller/MyStackView.swift+27 GDproject/Controller/PostViewCell.swift → GDproject/Controller/News/PostViewCell.swift+7−6 GDproject/Controller/NewsController.swift+7−2
GDproject.xcodeproj/project.pbxproj+13−1
@@ -27,6 +27,7 @@
2727 12E36DCC22144725006FCDD7 /* PostViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCB22144725006FCDD7 /* PostViewCell.swift */; };
2828 12E36DCE22144756006FCDD7 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DCD22144756006FCDD7 /* Constants.swift */; };
2929 12E36DD122148122006FCDD7 /* FullPostController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD022148122006FCDD7 /* FullPostController.swift */; };
30+ 12E36DD522156559006FCDD7 /* MyStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E36DD422156559006FCDD7 /* MyStackView.swift */; };
3031/* End PBXBuildFile section */
3132
3233/* Begin PBXCopyFilesBuildPhase section */
@@ -66,6 +67,7 @@
6667 12E36DCB22144725006FCDD7 /* PostViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewCell.swift; sourceTree = "<group>"; };
6768 12E36DCD22144756006FCDD7 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
6869 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>"; };
6971/* End PBXFileReference section */
7072
7173/* Begin PBXFrameworksBuildPhase section */
@@ -137,16 +139,25 @@
137139 12E36DCF22145923006FCDD7 /* Controller */ = {
138140 isa = PBXGroup;
139141 children = (
142+ 12E36DD422156559006FCDD7 /* MyStackView.swift */,
140143 12E36DD022148122006FCDD7 /* FullPostController.swift */,
141144 12E36DC522144266006FCDD7 /* HeaderNewsChannels.swift */,
142145 12E36DC722144374006FCDD7 /* ChannelsController.swift */,
143146 12E36D9D221424EA006FCDD7 /* NewsController.swift */,
144− 12E36DCB22144725006FCDD7 /* PostViewCell.swift */,
147+ 12E36DD322156519006FCDD7 /* News */,
145148 12E36DC922144635006FCDD7 /* NewPostViewController.swift */,
146149 );
147150 path = Controller;
148151 sourceTree = "<group>";
149152 };
153+ 12E36DD322156519006FCDD7 /* News */ = {
154+ isa = PBXGroup;
155+ children = (
156+ 12E36DCB22144725006FCDD7 /* PostViewCell.swift */,
157+ );
158+ path = News;
159+ sourceTree = "<group>";
160+ };
150161/* End PBXGroup section */
151162
152163/* Begin PBXNativeTarget section */
@@ -219,6 +230,7 @@
219230 isa = PBXSourcesBuildPhase;
220231 buildActionMask = 2147483647;
221232 files = (
233+ 12E36DD522156559006FCDD7 /* MyStackView.swift in Sources */,
222234 12E36DC822144374006FCDD7 /* ChannelsController.swift in Sources */,
223235 12E36DB922144016006FCDD7 /* User.swift in Sources */,
224236 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
GDproject/Controller/FullPostController.swift+70
@@ -7,6 +7,7 @@
77//
88
99import UIKit
10+import TinyConstraints
1011
1112class FullPostController: UITableViewController {
1213
@@ -16,8 +17,22 @@ class FullPostController: UITableViewController {
1617 super.viewDidLoad()
1718
1819 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
20+
21+ setUpNavigationBar()
22+ tableView.separatorStyle = .none
1923 }
2024
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+ }
2136 // MARK: - Table view data source
2237
2338 override func numberOfSections(in tableView: UITableView) -> Int {
@@ -25,6 +40,59 @@ class FullPostController: UITableViewController {
2540 return 2
2641 }
2742
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+ }
2896 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
2997 {
3098 switch section {
@@ -44,6 +112,8 @@ class FullPostController: UITableViewController {
44112 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
45113
46114 cell.fill(with: post!.dataArray, true)
115+ cell.selectionStyle = .none
47116 return cell
48117 }
118+
49119}
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
1616 let nameLabel: UILabel = {
1717 let label = UILabel()
1818 label.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
19− label.text = "vgogomazova"
19+ label.text = "vbogomazova"
2020 label.font = UIFont.boldSystemFont(ofSize: 16)
2121 return label
2222 }()
@@ -84,16 +84,17 @@ class PostViewCell: UITableViewCell
8484 let nameStackView = UIStackView(arrangedSubviews: [nameLabel, fullNameLabel])
8585 nameStackView.axis = .vertical
8686 contentView.addSubview(nameStackView)
87− nameStackView.height(46)
88− nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(16) + .right(16))
87+ //nameStackView.height(46)
88+ nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(20) + .right(20) + .top(8))
8989
90− let stackView = UIStackView(arrangedSubviews: views)
90+ let stackView = MyStackView(arrangedSubviews: views)
91+ stackView.isFull = full
9192 stackView.axis = .vertical
9293 contentView.addSubview(stackView)
9394 if !full {
9495 stackView.height(300, relation: .equalOrLess, isActive: true)
9596 }
96− stackView.topToBottom(of: nameStackView)
97− stackView.edgesToSuperview(excluding: .top, insets: .bottom(8) + .left(16) + .right(16))
97+ stackView.topToBottom(of: nameStackView, offset: 16, relation: .equal, isActive: true)
98+ stackView.edgesToSuperview(excluding: .top, insets: .left(16) + .right(16))
9899 }
99100}
GDproject/Controller/NewsController.swift+7−2
@@ -15,7 +15,7 @@ class NewsController: UIViewController
1515
1616 @IBOutlet weak var tableView: UITableView!
1717
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")]
1919
2020 override func viewDidLoad()
2121 {
@@ -34,6 +34,7 @@ class NewsController: UIViewController
3434 super.viewWillAppear(animated)
3535 navigationController?.navigationBar.prefersLargeTitles = true
3636 }
37+
3738 func setUpNavigationItemsforPosts(){
3839 navigationItem.title = "Posts"
3940 navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(self.writePost(_:)))]
@@ -71,6 +72,8 @@ class NewsController: UIViewController
7172extension NewsController: UITableViewDelegate{
7273 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
7374 {
75+ tableView.deselectRow(at: indexPath, animated: true)
76+
7477 let vc = storyboard!.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
7578
7679 vc.post = dataSourse[indexPath.row]
@@ -85,10 +88,12 @@ extension NewsController: UITableViewDataSource
8588 return dataSourse.count
8689 }
8790
88− func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
91+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
92+ {
8993 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
9094
9195 cell.fill(with: dataSourse[indexPath.row].dataArray, false)
96+ cell.selectionStyle = .none
9297 return cell
9398 }
9499