git.iko.soy/dashared/GDproject
on master help sign in
imported hashtags in postCellView. needs slight modifications
commit0586c414208b40443747806fe2cc96d56fa156b7 authorDarya Rednikina <rednikina.com@yandex.ru> dateSat 16 Feb 2019, 23:45 (8 years ago) parent30b7ba4
3 files changed+50−47
GDproject/Controller/News/FullPostController.swift+5−44 GDproject/Controller/News/NewsVC.swift+1−1 GDproject/Controller/News/PostViewCell.swift+44−2
GDproject/Controller/News/FullPostController.swift+5−44
@@ -53,49 +53,10 @@ class FullPostController: UITableViewController {
5353 }
5454
5555
56− override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
57− {
58− let mainView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
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− }
56+// override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
57+// {
58+//
59+// }
9960
10061
10162 override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
@@ -125,7 +86,7 @@ class FullPostController: UITableViewController {
12586
12687 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId) as! PostViewCell
12788
128− cell.fill(with: post!.dataArray, true)
89+ cell.fill(with: post!.dataArray, true, post: post!)
12990 cell.selectionStyle = .none
13091 return cell
13192 }
GDproject/Controller/News/NewsVC.swift+1−1
@@ -34,7 +34,7 @@ class NewsVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
3434 {
3535 let cell = tableView.dequeueReusableCell(withIdentifier: postCellId, for: indexPath) as! PostViewCell
3636
37− cell.fill(with: dataSourse[indexPath.row].dataArray, false)
37+ cell.fill(with: dataSourse[indexPath.row].dataArray, false, post: dataSourse[indexPath.row])
3838 cell.selectionStyle = .none
3939 return cell
4040 }
GDproject/Controller/News/PostViewCell.swift+44−2
@@ -69,9 +69,11 @@ class PostViewCell: UITableViewCell
6969
7070 var views: [UIView] = []
7171 var data : [UIImage] = []
72+ var post: Post?
7273
73− func fill(with info: [Media], _ isFullVersoin: Bool)
74+ func fill(with info: [Media], _ isFullVersoin: Bool, post: Post)
7475 {
76+ self.post = post
7577 // important
7678 contentView.subviews.forEach({ $0.removeFromSuperview() })
7779
@@ -99,6 +101,46 @@ class PostViewCell: UITableViewCell
99101 //nameStackView.height(46)
100102 nameStackView.edgesToSuperview(excluding: .bottom, insets: .left(20) + .right(20) + .top(8))
101103
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+
102144 let stackView = MyStackView(arrangedSubviews: views)
103145 stackView.isFull = full
104146 stackView.axis = .vertical
@@ -106,7 +148,7 @@ class PostViewCell: UITableViewCell
106148 if !full {
107149 stackView.height(300, relation: .equalOrLess, isActive: true)
108150 }
109− stackView.topToBottom(of: nameStackView, offset: 16, relation: .equal, isActive: true)
151+ stackView.topToBottom(of: mainView, offset: 16, relation: .equal, isActive: true)
110152 stackView.edgesToSuperview(excluding: [.top, .bottom], insets: .left(16) + .right(16))
111153
112154 let commentsSharesStackView = UIStackView(arrangedSubviews: [ commentsLabel, shareButton])