Commit 682eeab1 authored by Steven杜宇's avatar Steven杜宇

// 首页身份

parent 9f99ab39
...@@ -9,13 +9,29 @@ ...@@ -9,13 +9,29 @@
import UIKit import UIKit
import JXSegmentedView import JXSegmentedView
class YHHomeIdentityViewController: YHBaseViewController { class YHHomeIdentityItem {
var url: String = ""
var img: UIImage? = nil
var imgView: UIImageView = UIImageView()
func getSize() -> CGSize {
if let img = self.img, img.size.width > 0.0, img.size.height > 0.0{
return CGSize(width:img.size.width, height: (img.size.height/img.size.width) * KScreenWidth)
}
return CGSize(width: KScreenWidth, height: KScreenWidth)
}
init(url: String = "", img: UIImage? = nil) {
self.url = url
self.img = img
}
}
var imgs:[UIImage?] = [UIImage(named: "identity_talent_1"), class YHHomeIdentityViewController: YHBaseViewController {
UIImage(named: "identity_talent_2"),
UIImage(named: "identity_talent_3"),
UIImage(named: "identity_talent_4")]
var imgItems:[YHHomeIdentityItem] = [YHHomeIdentityItem(img:UIImage(named: "identity_talent_1")),
YHHomeIdentityItem(img:UIImage(named: "identity_talent_2")),
YHHomeIdentityItem(img:UIImage(named: "identity_talent_3")),
YHHomeIdentityItem(img:UIImage(named: "identity_talent_4"))]
lazy var subTabBar: YHIdentityTabBar = { lazy var subTabBar: YHIdentityTabBar = {
let items = [YHIdentityTabBarItem(title: "优才", type: .talent), let items = [YHIdentityTabBarItem(title: "优才", type: .talent),
YHIdentityTabBarItem(title: "高才", type: .high), YHIdentityTabBarItem(title: "高才", type: .high),
...@@ -25,6 +41,7 @@ class YHHomeIdentityViewController: YHBaseViewController { ...@@ -25,6 +41,7 @@ class YHHomeIdentityViewController: YHBaseViewController {
bar.selectBlock = { bar.selectBlock = {
[weak self] type in [weak self] type in
guard let self = self else { return } guard let self = self else { return }
self.tableView.setContentOffset(.zero, animated: true)
self.tableView.reloadData() self.tableView.reloadData()
if self.segmentedView.selectedIndex != 0 { if self.segmentedView.selectedIndex != 0 {
self.segmentedView.defaultSelectedIndex = 0 self.segmentedView.defaultSelectedIndex = 0
...@@ -159,25 +176,23 @@ extension YHHomeIdentityViewController: UITableViewDataSource, UITableViewDelega ...@@ -159,25 +176,23 @@ extension YHHomeIdentityViewController: UITableViewDataSource, UITableViewDelega
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHHomeIdentityCell.cellReuseIdentifier, for: indexPath) as! YHHomeIdentityCell let cell = tableView.dequeueReusableCell(withIdentifier: YHHomeIdentityCell.cellReuseIdentifier, for: indexPath) as! YHHomeIdentityCell
if 0 <= indexPath.row, indexPath.row < self.imgs.count { if 0 <= indexPath.row, indexPath.row < self.imgItems.count {
if let img = self.imgs[indexPath.row] { let item = self.imgItems[indexPath.row]
cell.image = img cell.image = item.img
}
} }
return cell return cell
} }
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if 0 <= indexPath.row, indexPath.row < self.imgs.count { if 0 <= indexPath.row, indexPath.row < self.imgItems.count {
if let img = self.imgs[indexPath.row] { let item = self.imgItems[indexPath.row]
return (img.size.height/img.size.width) * KScreenWidth return item.getSize().height
}
} }
return 0.0 return KScreenWidth
} }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.imgs.count return self.imgItems.count
} }
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
...@@ -196,3 +211,29 @@ extension YHHomeIdentityViewController: UITableViewDataSource, UITableViewDelega ...@@ -196,3 +211,29 @@ extension YHHomeIdentityViewController: UITableViewDataSource, UITableViewDelega
return UIView() return UIView()
} }
} }
extension YHHomeIdentityViewController {
func requestData() {
}
func requestImages() {
let ossGroup = DispatchGroup()
for item in self.imgItems {
ossGroup.enter()
item.imgView.kf.setImage(with: URL(string: item.url)) { result in
switch result {
case .success(let value):
item.img = value.image
case .failure(let error):
print("image download failed: \(error.localizedDescription)")
}
ossGroup.leave()
}
}
ossGroup.notify(queue: .main) {
self.tableView.reloadData()
}
}
}
...@@ -13,7 +13,14 @@ class YHHomeIdentityCell: UITableViewCell { ...@@ -13,7 +13,14 @@ class YHHomeIdentityCell: UITableViewCell {
static let cellReuseIdentifier = "YHHomeIdentityCell" static let cellReuseIdentifier = "YHHomeIdentityCell"
var image:UIImage? = UIImage(named: "global_default_image") { var image:UIImage? = UIImage(named: "global_default_image") {
didSet { didSet {
imgView.image = image if let img = image {
imgView.image = img
self.bottomLineView.isHidden = false
} else {
imgView.image = UIImage(named: "global_default_image")
self.bottomLineView.isHidden = false
}
} }
} }
...@@ -23,6 +30,12 @@ class YHHomeIdentityCell: UITableViewCell { ...@@ -23,6 +30,12 @@ class YHHomeIdentityCell: UITableViewCell {
return view return view
}() }()
lazy var bottomLineView: UIView = {
let view = UIView()
view.backgroundColor = .separatorColor
return view
}()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI() setupUI()
...@@ -34,8 +47,14 @@ class YHHomeIdentityCell: UITableViewCell { ...@@ -34,8 +47,14 @@ class YHHomeIdentityCell: UITableViewCell {
func setupUI() { func setupUI() {
self.contentView.addSubview(self.imgView) self.contentView.addSubview(self.imgView)
self.contentView.addSubview(self.bottomLineView)
self.imgView.snp.makeConstraints { make in self.imgView.snp.makeConstraints { make in
make.edges.equalToSuperview() make.edges.equalToSuperview()
} }
self.bottomLineView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(1.0)
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment