git.iko.soy/dashared/GDproject
on master help sign in
imported hashtags in postCellView. needs slight modifications
0586c41Darya Rednikina
GDproject/Controller/News/FullPostController.swift+5−44
@@ -53,49 +53,10 @@ class FullPostController: UITableViewController {
53 }
53 }
54
54
55
55
56− override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
56+// override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
57− {
57+// {
58− let mainView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
58+//
59−
60− let scrollView = UIScrollView()
61−
62− scrollView.backgroundColor = .white
63−
64− mainView.addSubview(scrollView)
65− scrollView.edgesToSuperview()
66−
67− scrollView.showsHorizontalScrollIndicator = false
68−
69− var buttons: [UIButton] = []
70− for hash in post!.hashtags {
71− let button = UIButton()
72− button.setTitle("#" + hash, for: .normal)
73− button.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
74− button.layer.cornerRadius = 10
75− button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
76− button.setTitleColor(.black, for: .normal)
77− buttons.append(button)
78− }
79−
80− let stackView = UIStackView(arrangedSubviews: buttons)
81−
82− scrollView.addSubview(stackView)
83−
84− stackView.axis = .horizontal
85− stackView.alignment = .center
86− stackView.spacing = 20
87−
88− stackView.edgesToSuperview(insets: .left(20) + .top(10) + .right(20))
89−
90− scrollView.contentSize = CGSize(width: 500, height: 50)
91−
92− switch section {
93− case 0:
94− return mainView
95− default:
96− return nil
97− }
98− }
59+// }
99
60
100
61
101 override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
62 override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
@@ -125,7 +86,7 @@ class FullPostController: UITableViewController {
125
86
126 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
87 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
127
88
128− cell.fill(with: post!.dataArray, true)
89+ cell.fill(with: post!.dataArray, true, post: post!)
129 cell.selectionStyle = .none
90 cell.selectionStyle = .none
130 return cell
91 return cell
131 }
92 }
GDproject/Controller/News/NewsVC.swift+1−1
@@ -34,7 +34,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
34 {
34 {
35 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
35 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
36
36
37− cell.fill(with: dataSourse[indexPath.row].dataArray, false)
37+ cell.fill(with: dataSourse[indexPath.row].dataArray, false, post: dataSourse[indexPath.row])
38 cell.selectionStyle = .none
38 cell.selectionStyle = .none
39 return cell
39 return cell
40 }
40 }
GDproject/Controller/News/PostViewCell.swift+44−2
@@ -69,9 +69,11 @@ class PostViewCell: UITableViewCell
69
69
70 var views: [UIView] = []
70 var views: [UIView] = []
71 var data : [UIImage] = []
71 var data : [UIImage] = []
72+ var post: Post?
72
73
73− func fill(with info: [Media], _ isFullVersoin: Bool)
74+ func fill(with info: [Media], _ isFullVersoin: Bool, post: Post)
74 {
75 {
76+ self.post = post
75 // important
77 // important
76 contentView.subviews.forEach({ $0.removeFromSuperview() })
78 contentView.subviews.forEach({ $0.removeFromSuperview() })
77
79
@@ -99,6 +101,46 @@ class PostViewCell: UITableViewCell
99 //nameStackView.height(46)
101 //nameStackView.height(46)
100 nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(20) + .right(20) + .top(8))
102 nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(20) + .right(20) + .top(8))
101
103
104+ let mainView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
105+
106+ let scrollView = UIScrollView()
107+
108+ scrollView.backgroundColor = .white
109+
110+ mainView.addSubview(scrollView)
111+ scrollView.edgesToSuperview()
112+
113+ scrollView.showsHorizontalScrollIndicator = false
114+
115+ var buttons: [UIButton] = []
116+ for hash in post!.hashtags {
117+ let button = UIButton()
118+ button.setTitle("#" + hash, for: .normal)
119+ button.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
120+ button.layer.cornerRadius = 10
121+ button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
122+ button.setTitleColor(.black, for: .normal)
123+ buttons.append(button)
124+ }
125+
126+ let stackViewHashTags = UIStackView(arrangedSubviews: buttons)
127+
128+ scrollView.addSubview(stackViewHashTags)
129+
130+ stackViewHashTags.axis = .horizontal
131+ stackViewHashTags.alignment = .center
132+ stackViewHashTags.spacing = 20
133+
134+ stackViewHashTags.edgesToSuperview(insets: .left(20) + .top(10) + .right(20))
135+
136+ scrollView.contentSize = CGSize(width: 500, height: 50)
137+
138+
139+ contentView.addSubview(mainView)
140+ mainView.edgesToSuperview(excluding: [.top, .bottom])
141+ mainView.topToBottom(of: nameStackView)
142+ mainView.height(50)
143+
102 let stackView = MyStackView(arrangedSubviews: views)
144 let stackView = MyStackView(arrangedSubviews: views)
103 stackView.isFull = full
145 stackView.isFull = full
104 stackView.axis = .vertical
146 stackView.axis = .vertical
@@ -106,7 +148,7 @@ class PostViewCell: UITableViewCell
106 if !full {
148 if !full {
107 stackView.height(300, relation: .equalOrLess, isActive: true)
149 stackView.height(300, relation: .equalOrLess, isActive: true)
108 }
150 }
109− stackView.topToBottom(of: nameStackView, offset: 16, relation: .equal, isActive: true)
151+ stackView.topToBottom(of: mainView, offset: 16, relation: .equal, isActive: true)
110 stackView.edgesToSuperview(excluding: [.top, .bottom], insets: .left(16) + .right(16))
152 stackView.edgesToSuperview(excluding: [.top, .bottom], insets: .left(16) + .right(16))
111
153
112 let commentsSharesStackView = UIStackView(arrangedSubviews: [ commentsLabel, shareButton])
154 let commentsSharesStackView = UIStackView(arrangedSubviews: [ commentsLabel, shareButton])