Skip to content

Commit

Permalink
单品页面
Browse files Browse the repository at this point in the history
  • Loading branch information
ZTXBEST committed Jul 12, 2017
1 parent b00b7ed commit f023447
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 12 deletions.
12 changes: 12 additions & 0 deletions DanTangSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
2706E0831F14C652009835DE /* TXProductModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2706E0821F14C652009835DE /* TXProductModel.swift */; };
271D42F71F0CCD4600E04A82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 271D42F61F0CCD4600E04A82 /* Assets.xcassets */; };
271D42F91F0CE0C500E04A82 /* NetworkTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 271D42F81F0CE0C500E04A82 /* NetworkTool.swift */; };
271D42FB1F0CE45800E04A82 /* TXHomeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 271D42FA1F0CE45800E04A82 /* TXHomeModel.swift */; };
27352EFE1F0F15AB000BDAE0 /* HomeContentVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27352EFD1F0F15AB000BDAE0 /* HomeContentVC.swift */; };
27352F001F0F1BF1000BDAE0 /* HomeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27352EFF1F0F1BF1000BDAE0 /* HomeCell.swift */; };
27352F021F0F591B000BDAE0 /* TXWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27352F011F0F591B000BDAE0 /* TXWebViewController.swift */; };
27544CF31F14A90000D046CF /* ProductCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27544CF21F14A90000D046CF /* ProductCell.swift */; };
276A83621F15B59B009B04A4 /* ProductDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 276A83611F15B59B009B04A4 /* ProductDetailVC.swift */; };
27DD2DBB1F0DD2FF009659ED /* TXHomeTopModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DD2DBA1F0DD2FF009659ED /* TXHomeTopModel.swift */; };
27DD2DBD1F0E00FB009659ED /* UIView+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27DD2DBC1F0E00FB009659ED /* UIView+Extension.swift */; };
27E00AAD1F0C95E800B010C4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E00AAC1F0C95E800B010C4 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -52,12 +55,15 @@

/* Begin PBXFileReference section */
022002614A328256DCA5494F /* Pods-DanTangSwift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DanTangSwift.release.xcconfig"; path = "Pods/Target Support Files/Pods-DanTangSwift/Pods-DanTangSwift.release.xcconfig"; sourceTree = "<group>"; };
2706E0821F14C652009835DE /* TXProductModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXProductModel.swift; sourceTree = "<group>"; };
271D42F61F0CCD4600E04A82 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
271D42F81F0CE0C500E04A82 /* NetworkTool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkTool.swift; sourceTree = "<group>"; };
271D42FA1F0CE45800E04A82 /* TXHomeModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXHomeModel.swift; sourceTree = "<group>"; };
27352EFD1F0F15AB000BDAE0 /* HomeContentVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeContentVC.swift; sourceTree = "<group>"; };
27352EFF1F0F1BF1000BDAE0 /* HomeCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HomeCell.swift; sourceTree = "<group>"; };
27352F011F0F591B000BDAE0 /* TXWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXWebViewController.swift; sourceTree = "<group>"; };
27544CF21F14A90000D046CF /* ProductCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductCell.swift; sourceTree = "<group>"; };
276A83611F15B59B009B04A4 /* ProductDetailVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductDetailVC.swift; sourceTree = "<group>"; };
27DD2DBA1F0DD2FF009659ED /* TXHomeTopModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TXHomeTopModel.swift; sourceTree = "<group>"; };
27DD2DBC1F0E00FB009659ED /* UIView+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Extension.swift"; sourceTree = "<group>"; };
27E00AA91F0C95E800B010C4 /* DanTangSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DanTangSwift.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -294,20 +300,23 @@
isa = PBXGroup;
children = (
27E00B0B1F0CB88F00B010C4 /* ProductVC.swift */,
276A83611F15B59B009B04A4 /* ProductDetailVC.swift */,
);
path = Controller;
sourceTree = "<group>";
};
27E00B021F0CB7B100B010C4 /* Model */ = {
isa = PBXGroup;
children = (
2706E0821F14C652009835DE /* TXProductModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
27E00B031F0CB7B100B010C4 /* View */ = {
isa = PBXGroup;
children = (
27544CF21F14A90000D046CF /* ProductCell.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -552,8 +561,11 @@
27E00AF21F0CB6CB00B010C4 /* UIColor+Extension.swift in Sources */,
27352EFE1F0F15AB000BDAE0 /* HomeContentVC.swift in Sources */,
27E00B0C1F0CB88F00B010C4 /* ProductVC.swift in Sources */,
276A83621F15B59B009B04A4 /* ProductDetailVC.swift in Sources */,
2706E0831F14C652009835DE /* TXProductModel.swift in Sources */,
27352F021F0F591B000BDAE0 /* TXWebViewController.swift in Sources */,
27352F001F0F1BF1000BDAE0 /* HomeCell.swift in Sources */,
27544CF31F14A90000D046CF /* ProductCell.swift in Sources */,
27E00AEE1F0CB6B200B010C4 /* TXBaseViewController.swift in Sources */,
27E00B0E1F0CB8DD00B010C4 /* ClassifyVC.swift in Sources */,
27E00AF51F0CB6D600B010C4 /* TXConst.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
11 changes: 6 additions & 5 deletions DanTangSwift/BaseVC/TXTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ class TXTabBarController: UITabBarController {

private func addChildViewControllers() {
addChildViewController(childController: HomeVC(), title: "单糖", imaged: "TabBar_home_23x23_")
addChildViewController(childController: HomeVC(), title: "单品", imaged: "TabBar_gift_23x23_")
addChildViewController(childController: HomeVC(), title: "分类", imaged: "TabBar_category_23x23_")
addChildViewController(childController: HomeVC(), title: "我的", imaged: "TabBar_me_boy_23x23_")
addChildViewController(childController: ProductVC(), title: "单品", imaged: "TabBar_gift_23x23_")
addChildViewController(childController: ClassifyVC(), title: "分类", imaged: "TabBar_category_23x23_")
addChildViewController(childController: MineVC(), title: "我的", imaged: "TabBar_me_boy_23x23_")
}

private func addChildViewController(childController:UIViewController,title:String,imaged:String) {
childController.tabBarItem.title=title;
childController.tabBarItem.image=UIImage(named:imaged);
// childController.tabBarItem.title=title
childController.title = title
childController.tabBarItem.image=UIImage(named:imaged)
childController.tabBarItem.selectedImage=UIImage(named:imaged+"selected")
let nav=TXNavigationController(rootViewController: childController)
addChildViewController(nav)
Expand Down
27 changes: 24 additions & 3 deletions DanTangSwift/BaseVC/TXWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import UIKit
import SVProgressHUD

class TXWebViewController: TXBaseViewController ,UIWebViewDelegate{

var webView = UIWebView()
var url = String()
var titleString = String()


override func viewDidLoad() {
super.viewDidLoad()
let webView = UIWebView()

self.configToolBar()
webView = UIWebView()
webView.frame = view.bounds
webView.scalesPageToFit = true
webView.dataDetectorTypes = .all
Expand All @@ -26,6 +27,19 @@ class TXWebViewController: TXBaseViewController ,UIWebViewDelegate{
webView.delegate = self
view.addSubview(webView)
}

func configToolBar() {
let backItem = UIBarButtonItem(image: UIImage(named:"checkUserType_backward_9x15_"), style: .plain, target: self, action: #selector(backButtonClick))

let flexItem0 = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)

let forwardItem = UIBarButtonItem(image: UIImage(named: "Category_PostCollectionSeeAll_nightMode_5x8_"), style: .plain, target: nil, action: nil)

let flexItem1 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

self.setToolbarItems([backItem,flexItem0,forwardItem,flexItem1], animated: true)
}
// MARK:-- webview的方法
func webViewDidStartLoad(_ webView: UIWebView) {
SVProgressHUD.showInfo(withStatus: "正在加载中...")
UIApplication.shared.isNetworkActivityIndicatorVisible = true
Expand All @@ -43,4 +57,11 @@ class TXWebViewController: TXBaseViewController ,UIWebViewDelegate{
func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
SVProgressHUD.showError(withStatus: error.localizedDescription)
}

//MARK:-- button Action
@objc private func backButtonClick() {
if (self.webView.canGoBack) {
self.webView.goBack()
}
}
}
1 change: 0 additions & 1 deletion DanTangSwift/Home/Controller/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class HomeVC: TXBaseViewController,UIScrollViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()
self.title = "单糖"
initNav()
requestData()
// Do any additional setup after loading the view.
Expand Down
102 changes: 102 additions & 0 deletions DanTangSwift/Product/Controller/ProductDetailVC.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// ProductDetailVC.swift
// DanTangSwift
//
// Created by 赵天旭 on 2017/7/12.
// Copyright © 2017年 ZTX. All rights reserved.
//

import UIKit

class ProductDetailVC: TXBaseViewController,UITableViewDelegate,UITableViewDataSource {
var tableView : UITableView?
var scrollView = UIScrollView()

override func viewDidLoad() {
super.viewDidLoad()

self.initTableView()
self.initHeaderView()
// Do any additional setup after loading the view.
}

private func initTableView() {
tableView = UITableView(frame: CGRect(x: 0, y: 64, width: KScreenWidth, height: KScreenHeight), style: .plain)
tableView?.backgroundColor = TXGlobalColor()
tableView?.delegate = self
tableView?.dataSource = self
tableView?.autoresizingMask = [.flexibleHeight,.flexibleWidth]
self.view.addSubview(tableView!)
}

private func initHeaderView() {
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 520))
headerView.backgroundColor = UIColor.white

scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 375))
scrollView.delegate = self
scrollView.backgroundColor = UIColor.red
headerView.addSubview(scrollView)

headerView.addSubview(self.titleLabel)
headerView.addSubview(self.priceLabel)
headerView.addSubview(self.descriptionLabel)

titleLabel.snp.makeConstraints { (make) in
make.top.equalTo(scrollView.snp.bottom)

}

tableView?.tableHeaderView = headerView
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
return cell
}

//MARK:--- 懒加载
//标题
private lazy var titleLabel : UILabel = {
let titleLabel = UILabel()
titleLabel.numberOfLines = 0
titleLabel.textColor = UIColor.black
return titleLabel
}()
//价格
private lazy var priceLabel : UILabel = {
let priceLabel = UILabel()
priceLabel.textColor = TXGlobalRedColor()
priceLabel.numberOfLines = 0
priceLabel.font = UIFont.systemFont(ofSize: 16)
return priceLabel
}()
//描述
private lazy var descriptionLabel : UILabel = {
let descriptionLabel = UILabel()
descriptionLabel.numberOfLines = 0
descriptionLabel.textColor = TXColor(r: 0, g: 0, b: 0, a: 0.6)
descriptionLabel.font = UIFont.systemFont(ofSize: 15)
return descriptionLabel
}()

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}
46 changes: 43 additions & 3 deletions DanTangSwift/Product/Controller/ProductVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,59 @@

import UIKit

class ProductVC: TXBaseViewController {
private let cellId = "collectionViewId"

var collecitonView = UICollectionView()
class ProductVC: TXBaseViewController,UICollectionViewDelegate,UICollectionViewDataSource {

var collectionView : UICollectionView?
var datas = [TXProductModel]()

override func viewDidLoad() {
super.viewDidLoad()
self.title = "单品"
self.initCollectionView()
self.requestData()
// Do any additional setup after loading the view.
}

private func requestData() {

NetworkTool.shared.loadProductData {[weak self] (data) in
self?.datas = data
self?.collectionView?.reloadData()
}
}

private func initCollectionView() {

let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5)
let width: CGFloat = (KScreenWidth - 20) / 2
let height: CGFloat = 245
layout.itemSize = CGSize(width: width, height: height)

collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
collectionView?.delegate = self
collectionView?.dataSource = self
collectionView?.frame = view.bounds
collectionView?.backgroundColor = view.backgroundColor
view.addSubview(collectionView!)

collectionView?.register(ProductCell.self, forCellWithReuseIdentifier: cellId)
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return datas.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! ProductCell
cell.model = datas[indexPath.row]
return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)

}

override func didReceiveMemoryWarning() {
Expand Down
49 changes: 49 additions & 0 deletions DanTangSwift/Product/Model/TXProductModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// TXProductModel.swift
// DanTangSwift
//
// Created by 赵天旭 on 2017/7/11.
// Copyright © 2017年 ZTX. All rights reserved.
//

import UIKit

class TXProductModel: NSObject {
var cover_image_url: String?
var created_at: Int?
var describe: String?
var editor_id: Int?
var favorites_count: Int?
var id: Int?
var image_urls: [String]?
var is_favorite: Bool?
var name: String?
var price: String?
var purchase_id: Int?
var purchase_status: Int?
var purchase_type: Int?
var purchase_url: String?
var updated_at: Int?
var url: String?

init(dict: [String: AnyObject]) {
super.init()
cover_image_url = dict["cover_image_url"] as? String
created_at = dict["created_at"] as? Int
describe = dict["description"] as? String
editor_id = dict["editor_id"] as? Int
favorites_count = dict["favorites_count"] as? Int
id = dict["id"] as? Int
image_urls = dict["image_urls"] as? [String]
is_favorite = dict["is_favorite"] as? Bool
name = dict["name"] as? String
price = dict["price"] as? String
purchase_id = dict["purchase_id"] as? Int
purchase_status = dict["purchase_status"] as? Int
purchase_type = dict["purchase_type"] as? Int
purchase_url = dict["purchase_url"] as? String
updated_at = dict["updated_at"] as? Int
url = dict["url"] as? String
}

}
Loading

0 comments on commit f023447

Please sign in to comment.