├── Sample_TableView
├── Assets.xcassets
│ ├── Contents.json
│ ├── addTb.imageset
│ │ ├── Group 2.png
│ │ ├── Group 2@2x.png
│ │ ├── Group 2@3x.png
│ │ └── Contents.json
│ ├── minusTb.imageset
│ │ ├── Group.png
│ │ ├── Group@2x.png
│ │ ├── Group@3x.png
│ │ └── Contents.json
│ ├── desert.imageset
│ │ ├── breakfast-chocolate-cream-264727.jpg
│ │ └── Contents.json
│ ├── glasses.imageset
│ │ ├── accessory-classic-close-up-371723.jpg
│ │ └── Contents.json
│ ├── cameralens.imageset
│ │ ├── black-black-wallpaper-camera-8792.jpg
│ │ └── Contents.json
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Product.swift
├── Info.plist
├── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.storyboard
├── Extension.swift
├── ViewController.swift
├── AppDelegate.swift
└── ProductCell.swift
├── Sample_TableView.xcodeproj
├── xcuserdata
│ └── kemalekren.xcuserdatad
│ │ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── project.pbxproj
└── README.md
/Sample_TableView/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/addTb.imageset/Group 2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/addTb.imageset/Group 2.png
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/minusTb.imageset/Group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/minusTb.imageset/Group.png
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/addTb.imageset/Group 2@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/addTb.imageset/Group 2@2x.png
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/addTb.imageset/Group 2@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/addTb.imageset/Group 2@3x.png
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/minusTb.imageset/Group@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/minusTb.imageset/Group@2x.png
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/minusTb.imageset/Group@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/minusTb.imageset/Group@3x.png
--------------------------------------------------------------------------------
/Sample_TableView.xcodeproj/xcuserdata/kemalekren.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/desert.imageset/breakfast-chocolate-cream-264727.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/desert.imageset/breakfast-chocolate-cream-264727.jpg
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/glasses.imageset/accessory-classic-close-up-371723.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/glasses.imageset/accessory-classic-close-up-371723.jpg
--------------------------------------------------------------------------------
/Sample_TableView.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/cameralens.imageset/black-black-wallpaper-camera-8792.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kemalekren/Sample-Custom-TableView-Project-/HEAD/Sample_TableView/Assets.xcassets/cameralens.imageset/black-black-wallpaper-camera-8792.jpg
--------------------------------------------------------------------------------
/Sample_TableView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Sample_TableView/Product.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Product.swift
3 | // Sample_TableView
4 | //
5 | // Created by Esat Kemal Ekren on 5.04.2018.
6 | // Copyright © 2018 Esat Kemal Ekren. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | struct Product {
12 |
13 | var productName : String
14 | var productImage : UIImage
15 | var productDesc : String
16 | }
17 |
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/desert.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "breakfast-chocolate-cream-264727.jpg",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/cameralens.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "black-black-wallpaper-camera-8792.jpg",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/glasses.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "accessory-classic-close-up-371723.jpg",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/Sample_TableView.xcodeproj/xcuserdata/kemalekren.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Sample_TableView.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/minusTb.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "Group.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "Group@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "Group@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/addTb.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "Group 2.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "Group 2@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "Group 2@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sample-Custom-TableView-Project-
2 |
3 | This is the sample Project which is included Xcode Project for the Custom Table View Cells. I created this project Xcode 9.3 and Swift 4.1
4 |
5 | ## Getting Started
6 |
7 | You can simply download and the inspect the code if you want to explore Custom TableView Cell. Also if you want to how this code written you could read the Medium Post of mine, I put down of the link.
8 |
9 | https://medium.com/@esatkemalekren/swift-create-custom-tableview-cell-with-programmatically-in-ios-835d3880513d
10 |
11 | ## Authors
12 |
13 | * **Esat Kemal Ekren** - *Initial work* - [kemalekren](https://github.com/kemalekren)
14 |
15 |
--------------------------------------------------------------------------------
/Sample_TableView/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIRequiredDeviceCapabilities
26 |
27 | armv7
28 |
29 | UISupportedInterfaceOrientations
30 |
31 | UIInterfaceOrientationPortrait
32 | UIInterfaceOrientationLandscapeLeft
33 | UIInterfaceOrientationLandscapeRight
34 |
35 | UISupportedInterfaceOrientations~ipad
36 |
37 | UIInterfaceOrientationPortrait
38 | UIInterfaceOrientationPortraitUpsideDown
39 | UIInterfaceOrientationLandscapeLeft
40 | UIInterfaceOrientationLandscapeRight
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/Sample_TableView/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Sample_TableView/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Sample_TableView/Extension.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Extension.swift
3 | // Sample_TableView
4 | //
5 | // Created by Esat Kemal Ekren on 5.04.2018.
6 | // Copyright © 2018 Esat Kemal Ekren. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | extension UIView {
12 |
13 | func anchor (top: NSLayoutYAxisAnchor?, left: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, right: NSLayoutXAxisAnchor?, paddingTop: CGFloat, paddingLeft: CGFloat, paddingBottom: CGFloat, paddingRight: CGFloat, width: CGFloat, height: CGFloat, enableInsets: Bool) {
14 | var topInset = CGFloat(0)
15 | var bottomInset = CGFloat(0)
16 |
17 | if #available(iOS 11, *), enableInsets {
18 | let insets = self.safeAreaInsets
19 | topInset = insets.top
20 | bottomInset = insets.bottom
21 |
22 | print("Top: \(topInset)")
23 | print("bottom: \(bottomInset)")
24 | }
25 |
26 | translatesAutoresizingMaskIntoConstraints = false
27 |
28 | if let top = top {
29 | self.topAnchor.constraint(equalTo: top, constant: paddingTop+topInset).isActive = true
30 | }
31 | if let left = left {
32 | self.leftAnchor.constraint(equalTo: left, constant: paddingLeft).isActive = true
33 | }
34 | if let right = right {
35 | rightAnchor.constraint(equalTo: right, constant: -paddingRight).isActive = true
36 | }
37 | if let bottom = bottom {
38 | bottomAnchor.constraint(equalTo: bottom, constant: -paddingBottom-bottomInset).isActive = true
39 | }
40 | if height != 0 {
41 | heightAnchor.constraint(equalToConstant: height).isActive = true
42 | }
43 | if width != 0 {
44 | widthAnchor.constraint(equalToConstant: width).isActive = true
45 | }
46 |
47 | }
48 |
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/Sample_TableView/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/Sample_TableView/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // Sample_TableView
4 | //
5 | // Created by Esat Kemal Ekren on 5.04.2018.
6 | // Copyright © 2018 Esat Kemal Ekren. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 |
12 |
13 | class ViewController: UITableViewController {
14 |
15 | let cellId = "cellId"
16 | var products : [Product] = [Product]()
17 |
18 | override func viewDidLoad() {
19 | super.viewDidLoad()
20 | createProductArray()
21 | tableView.register(ProductCell.self, forCellReuseIdentifier: cellId)
22 |
23 | // Do any additional setup after loading the view, typically from a nib.
24 |
25 | }
26 |
27 | override func didReceiveMemoryWarning() {
28 | super.didReceiveMemoryWarning()
29 | // Dispose of any resources that can be recreated.
30 | }
31 |
32 |
33 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
34 | let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! ProductCell
35 | let currentLastItem = products[indexPath.row]
36 | cell.product = currentLastItem
37 | cell.selectionStyle = UITableViewCellSelectionStyle.none
38 | return cell
39 | }
40 |
41 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
42 | return products.count
43 | }
44 |
45 | override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
46 | return 100
47 | }
48 |
49 |
50 | func createProductArray() {
51 | products.append(Product(productName: "Glasses", productImage: #imageLiteral(resourceName: "glasses") , productDesc: "This is best Glasses I've ever seen"))
52 | products.append(Product(productName: "Desert", productImage: #imageLiteral(resourceName: "desert") , productDesc: "This is so yummy"))
53 | products.append(Product(productName: "Camera Lens", productImage: #imageLiteral(resourceName: "cameralens"), productDesc: "I wish I had this camera lens"))
54 | }
55 | }
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/Sample_TableView/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // Sample_TableView
4 | //
5 | // Created by Esat Kemal Ekren on 5.04.2018.
6 | // Copyright © 2018 Esat Kemal Ekren. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 |
20 | window = UIWindow()
21 | window?.makeKeyAndVisible()
22 | let rootControoler = ViewController()
23 | window?.rootViewController = rootControoler
24 |
25 | return true
26 | }
27 |
28 | func applicationWillResignActive(_ application: UIApplication) {
29 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
30 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
31 | }
32 |
33 | func applicationDidEnterBackground(_ application: UIApplication) {
34 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
35 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
36 | }
37 |
38 | func applicationWillEnterForeground(_ application: UIApplication) {
39 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
40 | }
41 |
42 | func applicationDidBecomeActive(_ application: UIApplication) {
43 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
44 | }
45 |
46 | func applicationWillTerminate(_ application: UIApplication) {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/Sample_TableView/ProductCell.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ProductCell.swift
3 | // Sample_TableView
4 | //
5 | // Created by Esat Kemal Ekren on 5.04.2018.
6 | // Copyright © 2018 Esat Kemal Ekren. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | protocol ProductCellDelegate {
12 | func increaseNumber(cell: ProductCell,number : Int)
13 | func decreaseNumber(cell: ProductCell,number : Int)
14 | }
15 |
16 | class ProductCell : UITableViewCell {
17 | var delegate : ProductCellDelegate?
18 | let minValue = 0
19 |
20 | var product : Product? {
21 | didSet {
22 | productImage.image = product?.productImage
23 | productNameLabel.text = product?.productName
24 | productDescriptionLabel.text = product?.productDesc
25 | }
26 | }
27 |
28 |
29 | private let productNameLabel : UILabel = {
30 | let lbl = UILabel()
31 | lbl.textColor = .black
32 | lbl.font = UIFont.boldSystemFont(ofSize: 16)
33 | lbl.textAlignment = .left
34 | return lbl
35 | }()
36 |
37 |
38 | private let productDescriptionLabel : UILabel = {
39 | let lbl = UILabel()
40 | lbl.textColor = .black
41 | lbl.font = UIFont.systemFont(ofSize: 16)
42 | lbl.textAlignment = .left
43 | lbl.numberOfLines = 0
44 | return lbl
45 | }()
46 |
47 | private let decreaseButton : UIButton = {
48 | let btn = UIButton(type: .custom)
49 | btn.setImage(#imageLiteral(resourceName: "minusTb"), for: .normal)
50 | btn.imageView?.contentMode = .scaleAspectFill
51 | return btn
52 | }()
53 |
54 | private let increaseButton : UIButton = {
55 | let btn = UIButton(type: .custom)
56 | btn.setImage(#imageLiteral(resourceName: "addTb"), for: .normal)
57 | btn.imageView?.contentMode = .scaleAspectFill
58 | return btn
59 | }()
60 | var productQuantity : UILabel = {
61 | let label = UILabel()
62 | label.font = UIFont.boldSystemFont(ofSize: 16)
63 | label.textAlignment = .left
64 | label.text = "1"
65 | label.textColor = .black
66 | return label
67 |
68 | }()
69 |
70 | private let productImage : UIImageView = {
71 | let imgView = UIImageView(image: #imageLiteral(resourceName: "glasses"))
72 | imgView.contentMode = .scaleAspectFit
73 | imgView.clipsToBounds = true
74 | return imgView
75 | }()
76 |
77 | @objc func decreaseFunc() {
78 | changeQuantity(by: -1)
79 |
80 | }
81 |
82 | @objc func increaseFunc() {
83 | changeQuantity(by: 1)
84 | }
85 |
86 |
87 | func changeQuantity(by amount: Int) {
88 | var quality = Int(productQuantity.text!)!
89 | quality += amount
90 | if quality < minValue {
91 | quality = 0
92 | productQuantity.text = "0"
93 | } else {
94 | productQuantity.text = "\(quality)"
95 | }
96 | delegate?.decreaseNumber(cell: self, number: quality)
97 |
98 | }
99 |
100 |
101 | override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
102 | super.init(style: style, reuseIdentifier: reuseIdentifier)
103 |
104 | contentView.addSubview(productImage)
105 | contentView.addSubview(productNameLabel)
106 | contentView.addSubview(productDescriptionLabel)
107 |
108 |
109 | productImage.anchor(top: topAnchor, left: leftAnchor, bottom: bottomAnchor, right: nil, paddingTop: 5, paddingLeft: 5, paddingBottom: 5, paddingRight: 0, width: 90, height: 0, enableInsets: false)
110 | productNameLabel.anchor(top: topAnchor, left: productImage.rightAnchor, bottom: nil, right: nil, paddingTop: 20, paddingLeft: 10, paddingBottom: 0, paddingRight: 0, width: frame.size.width / 2, height: 0, enableInsets: false)
111 | productDescriptionLabel.anchor(top: productNameLabel.bottomAnchor, left: productImage.rightAnchor, bottom: nil, right: nil, paddingTop: 0, paddingLeft: 10, paddingBottom: 0, paddingRight: 0, width: frame.size.width / 2, height: 0, enableInsets: false)
112 |
113 |
114 | let stackView = UIStackView(arrangedSubviews: [decreaseButton,productQuantity,increaseButton])
115 | stackView.distribution = .equalSpacing
116 | stackView.axis = .horizontal
117 | stackView.spacing = 5
118 | contentView.addSubview(stackView)
119 | stackView.anchor(top: topAnchor, left: productNameLabel.rightAnchor, bottom: bottomAnchor, right: rightAnchor, paddingTop: 15, paddingLeft: 5, paddingBottom: 15, paddingRight: 10, width: 0, height: 70, enableInsets: false)
120 |
121 | increaseButton.addTarget(self, action: #selector(increaseFunc), for: .touchUpInside)
122 | decreaseButton.addTarget(self, action: #selector(decreaseFunc), for: .touchUpInside)
123 |
124 | }
125 |
126 | required init?(coder aDecoder: NSCoder) {
127 | fatalError("init(coder:) has not been implemented")
128 | }
129 |
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/Sample_TableView.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 50;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | ADCB690E20765649006AF9C9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADCB690D20765649006AF9C9 /* AppDelegate.swift */; };
11 | ADCB691020765649006AF9C9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADCB690F20765649006AF9C9 /* ViewController.swift */; };
12 | ADCB691320765649006AF9C9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ADCB691120765649006AF9C9 /* Main.storyboard */; };
13 | ADCB69152076564B006AF9C9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ADCB69142076564B006AF9C9 /* Assets.xcassets */; };
14 | ADCB69182076564B006AF9C9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ADCB69162076564B006AF9C9 /* LaunchScreen.storyboard */; };
15 | ADCB69202076591E006AF9C9 /* Product.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADCB691F2076591E006AF9C9 /* Product.swift */; };
16 | ADCB69222076650B006AF9C9 /* ProductCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADCB69212076650B006AF9C9 /* ProductCell.swift */; };
17 | ADCB692420766530006AF9C9 /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADCB692320766530006AF9C9 /* Extension.swift */; };
18 | /* End PBXBuildFile section */
19 |
20 | /* Begin PBXFileReference section */
21 | ADCB690A20765649006AF9C9 /* Sample_TableView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample_TableView.app; sourceTree = BUILT_PRODUCTS_DIR; };
22 | ADCB690D20765649006AF9C9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
23 | ADCB690F20765649006AF9C9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
24 | ADCB691220765649006AF9C9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
25 | ADCB69142076564B006AF9C9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
26 | ADCB69172076564B006AF9C9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
27 | ADCB69192076564B006AF9C9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
28 | ADCB691F2076591E006AF9C9 /* Product.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Product.swift; sourceTree = ""; };
29 | ADCB69212076650B006AF9C9 /* ProductCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductCell.swift; sourceTree = ""; };
30 | ADCB692320766530006AF9C9 /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = ""; };
31 | /* End PBXFileReference section */
32 |
33 | /* Begin PBXFrameworksBuildPhase section */
34 | ADCB690720765649006AF9C9 /* Frameworks */ = {
35 | isa = PBXFrameworksBuildPhase;
36 | buildActionMask = 2147483647;
37 | files = (
38 | );
39 | runOnlyForDeploymentPostprocessing = 0;
40 | };
41 | /* End PBXFrameworksBuildPhase section */
42 |
43 | /* Begin PBXGroup section */
44 | ADCB690120765649006AF9C9 = {
45 | isa = PBXGroup;
46 | children = (
47 | ADCB690C20765649006AF9C9 /* Sample_TableView */,
48 | ADCB690B20765649006AF9C9 /* Products */,
49 | );
50 | sourceTree = "";
51 | };
52 | ADCB690B20765649006AF9C9 /* Products */ = {
53 | isa = PBXGroup;
54 | children = (
55 | ADCB690A20765649006AF9C9 /* Sample_TableView.app */,
56 | );
57 | name = Products;
58 | sourceTree = "";
59 | };
60 | ADCB690C20765649006AF9C9 /* Sample_TableView */ = {
61 | isa = PBXGroup;
62 | children = (
63 | ADCB690D20765649006AF9C9 /* AppDelegate.swift */,
64 | ADCB690F20765649006AF9C9 /* ViewController.swift */,
65 | ADCB69212076650B006AF9C9 /* ProductCell.swift */,
66 | ADCB691F2076591E006AF9C9 /* Product.swift */,
67 | ADCB692320766530006AF9C9 /* Extension.swift */,
68 | ADCB691120765649006AF9C9 /* Main.storyboard */,
69 | ADCB69142076564B006AF9C9 /* Assets.xcassets */,
70 | ADCB69162076564B006AF9C9 /* LaunchScreen.storyboard */,
71 | ADCB69192076564B006AF9C9 /* Info.plist */,
72 | );
73 | path = Sample_TableView;
74 | sourceTree = "";
75 | };
76 | /* End PBXGroup section */
77 |
78 | /* Begin PBXNativeTarget section */
79 | ADCB690920765649006AF9C9 /* Sample_TableView */ = {
80 | isa = PBXNativeTarget;
81 | buildConfigurationList = ADCB691C2076564B006AF9C9 /* Build configuration list for PBXNativeTarget "Sample_TableView" */;
82 | buildPhases = (
83 | ADCB690620765649006AF9C9 /* Sources */,
84 | ADCB690720765649006AF9C9 /* Frameworks */,
85 | ADCB690820765649006AF9C9 /* Resources */,
86 | );
87 | buildRules = (
88 | );
89 | dependencies = (
90 | );
91 | name = Sample_TableView;
92 | productName = Sample_TableView;
93 | productReference = ADCB690A20765649006AF9C9 /* Sample_TableView.app */;
94 | productType = "com.apple.product-type.application";
95 | };
96 | /* End PBXNativeTarget section */
97 |
98 | /* Begin PBXProject section */
99 | ADCB690220765649006AF9C9 /* Project object */ = {
100 | isa = PBXProject;
101 | attributes = {
102 | LastSwiftUpdateCheck = 0930;
103 | LastUpgradeCheck = 0930;
104 | ORGANIZATIONNAME = "Esat Kemal Ekren";
105 | TargetAttributes = {
106 | ADCB690920765649006AF9C9 = {
107 | CreatedOnToolsVersion = 9.3;
108 | };
109 | };
110 | };
111 | buildConfigurationList = ADCB690520765649006AF9C9 /* Build configuration list for PBXProject "Sample_TableView" */;
112 | compatibilityVersion = "Xcode 9.3";
113 | developmentRegion = en;
114 | hasScannedForEncodings = 0;
115 | knownRegions = (
116 | en,
117 | Base,
118 | );
119 | mainGroup = ADCB690120765649006AF9C9;
120 | productRefGroup = ADCB690B20765649006AF9C9 /* Products */;
121 | projectDirPath = "";
122 | projectRoot = "";
123 | targets = (
124 | ADCB690920765649006AF9C9 /* Sample_TableView */,
125 | );
126 | };
127 | /* End PBXProject section */
128 |
129 | /* Begin PBXResourcesBuildPhase section */
130 | ADCB690820765649006AF9C9 /* Resources */ = {
131 | isa = PBXResourcesBuildPhase;
132 | buildActionMask = 2147483647;
133 | files = (
134 | ADCB69182076564B006AF9C9 /* LaunchScreen.storyboard in Resources */,
135 | ADCB69152076564B006AF9C9 /* Assets.xcassets in Resources */,
136 | ADCB691320765649006AF9C9 /* Main.storyboard in Resources */,
137 | );
138 | runOnlyForDeploymentPostprocessing = 0;
139 | };
140 | /* End PBXResourcesBuildPhase section */
141 |
142 | /* Begin PBXSourcesBuildPhase section */
143 | ADCB690620765649006AF9C9 /* Sources */ = {
144 | isa = PBXSourcesBuildPhase;
145 | buildActionMask = 2147483647;
146 | files = (
147 | ADCB692420766530006AF9C9 /* Extension.swift in Sources */,
148 | ADCB691020765649006AF9C9 /* ViewController.swift in Sources */,
149 | ADCB69222076650B006AF9C9 /* ProductCell.swift in Sources */,
150 | ADCB690E20765649006AF9C9 /* AppDelegate.swift in Sources */,
151 | ADCB69202076591E006AF9C9 /* Product.swift in Sources */,
152 | );
153 | runOnlyForDeploymentPostprocessing = 0;
154 | };
155 | /* End PBXSourcesBuildPhase section */
156 |
157 | /* Begin PBXVariantGroup section */
158 | ADCB691120765649006AF9C9 /* Main.storyboard */ = {
159 | isa = PBXVariantGroup;
160 | children = (
161 | ADCB691220765649006AF9C9 /* Base */,
162 | );
163 | name = Main.storyboard;
164 | sourceTree = "";
165 | };
166 | ADCB69162076564B006AF9C9 /* LaunchScreen.storyboard */ = {
167 | isa = PBXVariantGroup;
168 | children = (
169 | ADCB69172076564B006AF9C9 /* Base */,
170 | );
171 | name = LaunchScreen.storyboard;
172 | sourceTree = "";
173 | };
174 | /* End PBXVariantGroup section */
175 |
176 | /* Begin XCBuildConfiguration section */
177 | ADCB691A2076564B006AF9C9 /* Debug */ = {
178 | isa = XCBuildConfiguration;
179 | buildSettings = {
180 | ALWAYS_SEARCH_USER_PATHS = NO;
181 | CLANG_ANALYZER_NONNULL = YES;
182 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
184 | CLANG_CXX_LIBRARY = "libc++";
185 | CLANG_ENABLE_MODULES = YES;
186 | CLANG_ENABLE_OBJC_ARC = YES;
187 | CLANG_ENABLE_OBJC_WEAK = YES;
188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
189 | CLANG_WARN_BOOL_CONVERSION = YES;
190 | CLANG_WARN_COMMA = YES;
191 | CLANG_WARN_CONSTANT_CONVERSION = YES;
192 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
193 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
194 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
195 | CLANG_WARN_EMPTY_BODY = YES;
196 | CLANG_WARN_ENUM_CONVERSION = YES;
197 | CLANG_WARN_INFINITE_RECURSION = YES;
198 | CLANG_WARN_INT_CONVERSION = YES;
199 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
200 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
201 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
203 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
204 | CLANG_WARN_STRICT_PROTOTYPES = YES;
205 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
206 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
207 | CLANG_WARN_UNREACHABLE_CODE = YES;
208 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
209 | CODE_SIGN_IDENTITY = "iPhone Developer";
210 | COPY_PHASE_STRIP = NO;
211 | DEBUG_INFORMATION_FORMAT = dwarf;
212 | ENABLE_STRICT_OBJC_MSGSEND = YES;
213 | ENABLE_TESTABILITY = YES;
214 | GCC_C_LANGUAGE_STANDARD = gnu11;
215 | GCC_DYNAMIC_NO_PIC = NO;
216 | GCC_NO_COMMON_BLOCKS = YES;
217 | GCC_OPTIMIZATION_LEVEL = 0;
218 | GCC_PREPROCESSOR_DEFINITIONS = (
219 | "DEBUG=1",
220 | "$(inherited)",
221 | );
222 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
223 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
224 | GCC_WARN_UNDECLARED_SELECTOR = YES;
225 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
226 | GCC_WARN_UNUSED_FUNCTION = YES;
227 | GCC_WARN_UNUSED_VARIABLE = YES;
228 | IPHONEOS_DEPLOYMENT_TARGET = 11.3;
229 | MTL_ENABLE_DEBUG_INFO = YES;
230 | ONLY_ACTIVE_ARCH = YES;
231 | SDKROOT = iphoneos;
232 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
233 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
234 | };
235 | name = Debug;
236 | };
237 | ADCB691B2076564B006AF9C9 /* Release */ = {
238 | isa = XCBuildConfiguration;
239 | buildSettings = {
240 | ALWAYS_SEARCH_USER_PATHS = NO;
241 | CLANG_ANALYZER_NONNULL = YES;
242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
244 | CLANG_CXX_LIBRARY = "libc++";
245 | CLANG_ENABLE_MODULES = YES;
246 | CLANG_ENABLE_OBJC_ARC = YES;
247 | CLANG_ENABLE_OBJC_WEAK = YES;
248 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
249 | CLANG_WARN_BOOL_CONVERSION = YES;
250 | CLANG_WARN_COMMA = YES;
251 | CLANG_WARN_CONSTANT_CONVERSION = YES;
252 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
253 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
254 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
255 | CLANG_WARN_EMPTY_BODY = YES;
256 | CLANG_WARN_ENUM_CONVERSION = YES;
257 | CLANG_WARN_INFINITE_RECURSION = YES;
258 | CLANG_WARN_INT_CONVERSION = YES;
259 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
260 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
261 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
263 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
264 | CLANG_WARN_STRICT_PROTOTYPES = YES;
265 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
266 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
267 | CLANG_WARN_UNREACHABLE_CODE = YES;
268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
269 | CODE_SIGN_IDENTITY = "iPhone Developer";
270 | COPY_PHASE_STRIP = NO;
271 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
272 | ENABLE_NS_ASSERTIONS = NO;
273 | ENABLE_STRICT_OBJC_MSGSEND = YES;
274 | GCC_C_LANGUAGE_STANDARD = gnu11;
275 | GCC_NO_COMMON_BLOCKS = YES;
276 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
277 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
278 | GCC_WARN_UNDECLARED_SELECTOR = YES;
279 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
280 | GCC_WARN_UNUSED_FUNCTION = YES;
281 | GCC_WARN_UNUSED_VARIABLE = YES;
282 | IPHONEOS_DEPLOYMENT_TARGET = 11.3;
283 | MTL_ENABLE_DEBUG_INFO = NO;
284 | SDKROOT = iphoneos;
285 | SWIFT_COMPILATION_MODE = wholemodule;
286 | SWIFT_OPTIMIZATION_LEVEL = "-O";
287 | VALIDATE_PRODUCT = YES;
288 | };
289 | name = Release;
290 | };
291 | ADCB691D2076564B006AF9C9 /* Debug */ = {
292 | isa = XCBuildConfiguration;
293 | buildSettings = {
294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
295 | CODE_SIGN_IDENTITY = "iPhone Developer";
296 | CODE_SIGN_STYLE = Automatic;
297 | DEVELOPMENT_TEAM = ALGWK3D6BW;
298 | INFOPLIST_FILE = Sample_TableView/Info.plist;
299 | LD_RUNPATH_SEARCH_PATHS = (
300 | "$(inherited)",
301 | "@executable_path/Frameworks",
302 | );
303 | PRODUCT_BUNDLE_IDENTIFIER = "idealistyazilim.com.Sample-TableView";
304 | PRODUCT_NAME = "$(TARGET_NAME)";
305 | PROVISIONING_PROFILE_SPECIFIER = "";
306 | SWIFT_VERSION = 4.0;
307 | TARGETED_DEVICE_FAMILY = "1,2";
308 | };
309 | name = Debug;
310 | };
311 | ADCB691E2076564B006AF9C9 /* Release */ = {
312 | isa = XCBuildConfiguration;
313 | buildSettings = {
314 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
315 | CODE_SIGN_IDENTITY = "iPhone Developer";
316 | CODE_SIGN_STYLE = Automatic;
317 | DEVELOPMENT_TEAM = ALGWK3D6BW;
318 | INFOPLIST_FILE = Sample_TableView/Info.plist;
319 | LD_RUNPATH_SEARCH_PATHS = (
320 | "$(inherited)",
321 | "@executable_path/Frameworks",
322 | );
323 | PRODUCT_BUNDLE_IDENTIFIER = "idealistyazilim.com.Sample-TableView";
324 | PRODUCT_NAME = "$(TARGET_NAME)";
325 | PROVISIONING_PROFILE_SPECIFIER = "";
326 | SWIFT_VERSION = 4.0;
327 | TARGETED_DEVICE_FAMILY = "1,2";
328 | };
329 | name = Release;
330 | };
331 | /* End XCBuildConfiguration section */
332 |
333 | /* Begin XCConfigurationList section */
334 | ADCB690520765649006AF9C9 /* Build configuration list for PBXProject "Sample_TableView" */ = {
335 | isa = XCConfigurationList;
336 | buildConfigurations = (
337 | ADCB691A2076564B006AF9C9 /* Debug */,
338 | ADCB691B2076564B006AF9C9 /* Release */,
339 | );
340 | defaultConfigurationIsVisible = 0;
341 | defaultConfigurationName = Release;
342 | };
343 | ADCB691C2076564B006AF9C9 /* Build configuration list for PBXNativeTarget "Sample_TableView" */ = {
344 | isa = XCConfigurationList;
345 | buildConfigurations = (
346 | ADCB691D2076564B006AF9C9 /* Debug */,
347 | ADCB691E2076564B006AF9C9 /* Release */,
348 | );
349 | defaultConfigurationIsVisible = 0;
350 | defaultConfigurationName = Release;
351 | };
352 | /* End XCConfigurationList section */
353 | };
354 | rootObject = ADCB690220765649006AF9C9 /* Project object */;
355 | }
356 |
--------------------------------------------------------------------------------