Skip to content
This repository has been archived by the owner on Dec 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from tribalmedia/dev
Browse files Browse the repository at this point in the history
Merge dev into master
  • Loading branch information
minhlau authored Aug 9, 2018
2 parents 9e0418b + b5fe57c commit d0200bf
Show file tree
Hide file tree
Showing 21 changed files with 942 additions and 255 deletions.
8 changes: 8 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
096953D720B5216D0057BFEE /* FMImageView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 096953CF20B520E10057BFEE /* FMImageView.framework */; };
096953D820B5216D0057BFEE /* FMImageView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 096953CF20B520E10057BFEE /* FMImageView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
09F663C220DC970000AB2B8A /* funmee.png in Resources */ = {isa = PBXBuildFile; fileRef = 09F663C120DC970000AB2B8A /* funmee.png */; };
AB5E53032112A14700F24D8A /* PhotoGrid.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB5E53002112A14700F24D8A /* PhotoGrid.swift */; };
ABAE8A8620EDBAE500383EEC /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABAE8A8520EDBAE500383EEC /* TableViewController.swift */; };
ABAE8A8A20EDBCF600383EEC /* ImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABAE8A8920EDBCF600383EEC /* ImageCell.swift */; };
ABB852BA21182EB200CC3CA6 /* FMImageViewBottomView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB852B921182EB200CC3CA6 /* FMImageViewBottomView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -76,8 +78,10 @@
096953BF20B520C80057BFEE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
096953C820B520E10057BFEE /* FMImageView.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FMImageView.xcodeproj; path = ../FMImageView/FMImageView.xcodeproj; sourceTree = "<group>"; };
09F663C120DC970000AB2B8A /* funmee.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = funmee.png; sourceTree = "<group>"; };
AB5E53002112A14700F24D8A /* PhotoGrid.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotoGrid.swift; sourceTree = "<group>"; };
ABAE8A8520EDBAE500383EEC /* TableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
ABAE8A8920EDBCF600383EEC /* ImageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCell.swift; sourceTree = "<group>"; };
ABB852B921182EB200CC3CA6 /* FMImageViewBottomView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FMImageViewBottomView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -121,9 +125,11 @@
096953A720B520C50057BFEE /* Example */ = {
isa = PBXGroup;
children = (
AB5E53002112A14700F24D8A /* PhotoGrid.swift */,
096953A820B520C50057BFEE /* AppDelegate.swift */,
ABAE8A8520EDBAE500383EEC /* TableViewController.swift */,
ABAE8A8920EDBCF600383EEC /* ImageCell.swift */,
ABB852B921182EB200CC3CA6 /* FMImageViewBottomView.swift */,
096953AC20B520C50057BFEE /* Main.storyboard */,
096953AF20B520C80057BFEE /* Assets.xcassets */,
096953B120B520C80057BFEE /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -278,8 +284,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ABB852BA21182EB200CC3CA6 /* FMImageViewBottomView.swift in Sources */,
ABAE8A8A20EDBCF600383EEC /* ImageCell.swift in Sources */,
ABAE8A8620EDBAE500383EEC /* TableViewController.swift in Sources */,
AB5E53032112A14700F24D8A /* PhotoGrid.swift in Sources */,
096953A920B520C50057BFEE /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
38 changes: 29 additions & 9 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Alignment constraints with different attributes" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -20,28 +21,47 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<inset key="separatorInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="tableCell" rowHeight="109" id="pkQ-CB-K9I" customClass="ImageCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="109"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="tableCell" rowHeight="293" id="pkQ-CB-K9I" customClass="ImageCell" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="293"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="pkQ-CB-K9I" id="aIF-ON-7xJ">
<rect key="frame" x="0.0" y="0.0" width="375" height="109"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="293"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="gdw-00-HIk">
<rect key="frame" x="70" y="29" width="50" height="50"/>
<rect key="frame" x="48" y="31" width="88" height="88"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="VkA-bQ-R4p"/>
<constraint firstAttribute="width" constant="50" id="tCf-RW-nNb"/>
<constraint firstAttribute="width" constant="88" id="3rx-0v-Lhh"/>
<constraint firstAttribute="height" constant="88" id="PrK-cn-ASg"/>
</constraints>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="wcS-Oi-xbn">
<rect key="frame" x="16" y="11" width="343" height="260"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="260" id="Ciy-mv-rVl"/>
</constraints>
</view>
</subviews>
<constraints>
<constraint firstItem="gdw-00-HIk" firstAttribute="top" secondItem="aIF-ON-7xJ" secondAttribute="topMargin" constant="18" id="2Zu-XJ-1wE"/>
<constraint firstItem="gdw-00-HIk" firstAttribute="leading" secondItem="aIF-ON-7xJ" secondAttribute="leadingMargin" constant="54" id="3M5-kk-Z0j"/>
<constraint firstAttribute="bottomMargin" secondItem="gdw-00-HIk" secondAttribute="bottom" constant="19" id="RSS-9B-tV9"/>
<constraint firstItem="wcS-Oi-xbn" firstAttribute="trailing" secondItem="aIF-ON-7xJ" secondAttribute="trailingMargin" id="5Qf-ea-gYx"/>
<constraint firstItem="wcS-Oi-xbn" firstAttribute="leading" secondItem="aIF-ON-7xJ" secondAttribute="leadingMargin" id="5X1-P3-Zcw"/>
<constraint firstItem="gdw-00-HIk" firstAttribute="leading" secondItem="aIF-ON-7xJ" secondAttribute="leadingMargin" constant="32" id="8od-Df-utR"/>
<constraint firstItem="wcS-Oi-xbn" firstAttribute="top" secondItem="aIF-ON-7xJ" secondAttribute="topMargin" id="LdJ-FN-5MH"/>
<constraint firstAttribute="bottomMargin" secondItem="wcS-Oi-xbn" secondAttribute="bottom" constant="11" id="Re7-pi-op1"/>
<constraint firstItem="gdw-00-HIk" firstAttribute="top" secondItem="aIF-ON-7xJ" secondAttribute="topMargin" constant="20" id="bjE-WM-eRB"/>
<constraint firstAttribute="trailingMargin" secondItem="gdw-00-HIk" secondAttribute="trailing" constant="223" id="f0L-Nn-Oqm"/>
<constraint firstAttribute="bottomMargin" secondItem="gdw-00-HIk" secondAttribute="bottom" constant="78" id="vAc-EV-b5q"/>
</constraints>
<variation key="default">
<mask key="subviews">
<exclude reference="gdw-00-HIk"/>
</mask>
</variation>
</tableViewCellContentView>
<connections>
<outlet property="photoGridHeightConstraint" destination="Ciy-mv-rVl" id="7TL-fu-M5v"/>
<outlet property="photoGridView" destination="wcS-Oi-xbn" id="sdt-Pv-31G"/>
<outlet property="photoImageView" destination="gdw-00-HIk" id="dka-z7-ECB"/>
</connections>
</tableViewCell>
Expand Down
119 changes: 119 additions & 0 deletions Example/Example/FMImageViewBottomView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// FMImageViewBottomView.swift
// Example
//
// Created by Trần Quang Minh on 8/6/18.
// Copyright © 2018 Hoang Trong Anh. All rights reserved.
//

import UIKit

class FMImageViewBottomView: UIView {
var stackView: UIStackView?

var subAreaBottomView: [(button: UIButton, label: UILabel)] = []

override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}


func commonInit() {
let likeButton = UIButton()
likeButton.setImage(#imageLiteral(resourceName: "icn_like"), for: .normal)
likeButton.isUserInteractionEnabled = true
likeButton.addTarget(self, action: #selector(target1(_:)), for: .touchUpInside)
let label = UILabel()
label.text = "10"

let button1 = UIButton()
button1.setImage(#imageLiteral(resourceName: "icn_comment"), for: .normal)
button1.isUserInteractionEnabled = true
button1.addTarget(self, action: #selector(target2(_:)), for: .touchUpInside)
let label1 = UILabel()
label1.text = "20"

self.subAreaBottomView.append((button: likeButton, label: label))
self.subAreaBottomView.append((button: button1, label: label1))

self.stackView = UIStackView()


self.stackView?.translatesAutoresizingMaskIntoConstraints = false
self.stackView?.heightAnchor.constraint(equalToConstant: 40).isActive = true

self.stackView?.backgroundColor = .red
self.stackView?.alignment = .center
self.stackView?.distribution = .equalSpacing
self.stackView?.axis = .horizontal
self.stackView?.spacing = 0

self.stackView?.autoresizingMask = [.flexibleWidth, .flexibleHeight, .flexibleBottomMargin]

self.addSubview(self.stackView!)

self.stackView?.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true
self.stackView?.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 0).isActive = true
self.stackView?.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 0).isActive = true

for value in subAreaBottomView {
let stack = UIView()

stack.heightAnchor.constraint(equalToConstant: 40).isActive = true
stack.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width / CGFloat(self.subAreaBottomView.count)).isActive = true

let subStack = UIView()
subStack.translatesAutoresizingMaskIntoConstraints = false
subStack.heightAnchor.constraint(equalToConstant: 40 / 2).isActive = true

// items of sub view
// ** Buttons **
value.button.translatesAutoresizingMaskIntoConstraints = false
value.button.heightAnchor.constraint(equalToConstant: 50).isActive = true
value.button.widthAnchor.constraint(equalToConstant: 50).isActive = true

subStack.addSubview(value.button)

// ** Labels **
value.button.leftAnchor.constraint(equalTo: subStack.leftAnchor, constant: 0).isActive = true

value.label.translatesAutoresizingMaskIntoConstraints = false
value.label.heightAnchor.constraint(equalToConstant: 40 / 2).isActive = true
value.label.numberOfLines = 1
value.label.font = UIFont.systemFont(ofSize: 20.0, weight: .bold)
value.label.textColor = .white

subStack.addSubview(value.label)

// ** Buttons **
value.button.leadingAnchor.constraint(equalTo: subStack.leadingAnchor, constant: 0).isActive = true
value.button.centerYAnchor.constraint(equalTo: subStack.centerYAnchor, constant: 0).isActive = true

// ** Labels **
value.label.trailingAnchor.constraint(equalTo: subStack.trailingAnchor, constant: 0).isActive = true
value.label.leftAnchor.constraint(equalTo: value.button.rightAnchor, constant: 10).isActive = true
value.label.centerYAnchor.constraint(equalTo: subStack.centerYAnchor, constant: 0).isActive = true

stack.addSubview(subStack)

// ** subview inside stack **
subStack.centerYAnchor.constraint(equalTo: stack.centerYAnchor, constant: 0).isActive = true
subStack.centerXAnchor.constraint(equalTo: stack.centerXAnchor, constant: 0).isActive = true

self.stackView?.addArrangedSubview(stack)
}
}

@objc func target1(_ sender: UIButton) {
print(#function)
}

@objc func target2(_ sender: UIButton) {
print(#function)
}
}
29 changes: 29 additions & 0 deletions Example/Example/ImageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,47 @@ import UIKit
class ImageCell: UITableViewCell {

@IBOutlet weak var photoImageView: UIImageView!
@IBOutlet weak var photoGridView: UIView!
@IBOutlet weak var photoGridHeightConstraint: NSLayoutConstraint!

var presentFMImageView: ((_ index: Int, _ imageView: UIImageView, _ photoURLs: [URL]) -> Void)?

var photoGrid = PhotoGridView(frame: CGRect.zero)
private var photoUrl: [URL] = [URL(string: "https://media.funmee.jp/medias/6a6bdd8326c225b806021f39e19ed97b1cff8cc5/large.jpg")!,
URL(string: "https://media.funmee.jp/medias/abbdda21d9c5859871bb88b521f6b4d2ab41601a/large.jpg")!,
URL(string: "https://media.funmee.jp/medias/2833d8826ab34e3b9304b62bd3b4bda0164f8004/large.JPG")!,
URL(string: "https://media.funmee.jp/medias/c455f72e904fbe0b22f44084c785f63a5367a54d/large.jpg")!]

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.photoImageView.contentMode = .scaleAspectFill
self.photoImageView.clipsToBounds = true

photoGrid.delegate = self
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

func updateCell() {
let photoGridWidth = UIScreen.main.bounds.width - 16 * 2
photoGrid.frame = CGRect(x: 0, y: 0, width: photoGridWidth, height: photoGridWidth)
photoGrid.photoUrl = photoUrl
photoGridHeightConstraint.constant = photoGrid.frame.height
for view in photoGridView.subviews {
view.removeFromSuperview()
}
photoGridView.addSubview(photoGrid)
}

}

extension ImageCell: PhotoGridDelegate {
func didSelect(index: Int, imageView: UIImageView) {
self.presentFMImageView?(index, imageView, self.photoUrl)
}
}
Loading

0 comments on commit d0200bf

Please sign in to comment.