Skip to content

Commit

Permalink
Merge pull request #1 from native-mobile-app-developers/2.0
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
sachithamh authored Oct 31, 2020
2 parents e6d92f5 + fc7b0a2 commit 4c91afe
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 75 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Example/SwiftStickerView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 4K9P34469L;
LastSwiftMigration = 0900;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 4K9P34469L;
LastSwiftMigration = 0900;
TestTargetID = 607FACCF1AFB9204008FA782;
};
Expand Down Expand Up @@ -478,6 +480,7 @@
baseConfigurationReference = AE402CC2380DD326BC90FB11 /* Pods-SwiftStickerView_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 4K9P34469L;
INFOPLIST_FILE = SwiftStickerView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -494,6 +497,7 @@
baseConfigurationReference = D188173DBC5DE8D6DCA34D61 /* Pods-SwiftStickerView_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 4K9P34469L;
INFOPLIST_FILE = SwiftStickerView/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -509,6 +513,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 0F750105565346444E0A2BAC /* Pods-SwiftStickerView_Tests.debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = 4K9P34469L;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -531,6 +536,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 717F402D2DF22B6661819DA2 /* Pods-SwiftStickerView_Tests.release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = 4K9P34469L;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
Expand Down
17 changes: 13 additions & 4 deletions Example/SwiftStickerView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17156" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17126"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -22,10 +23,18 @@
<rect key="frame" x="45" y="600" width="37" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="square.fill" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="mUA-qT-qBD">
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="flip.horizontal.fill" catalog="system" translatesAutoresizingMaskIntoConstraints="NO" id="mUA-qT-qBD">
<rect key="frame" x="96" y="600" width="37" height="37"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="AqM-pY-UEx">
<rect key="frame" x="197" y="617" width="162" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Show Hide EditBoundry"/>
<connections>
<action selector="showHideEditView:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="j0b-Za-HaJ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
Expand All @@ -36,7 +45,7 @@
</scene>
</scenes>
<resources>
<image name="flip.horizontal.fill" catalog="system" width="128" height="112"/>
<image name="gobackward" catalog="system" width="121" height="128"/>
<image name="square.fill" catalog="system" width="128" height="114"/>
</resources>
</document>
12 changes: 9 additions & 3 deletions Example/SwiftStickerView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ import SwiftStickerView
class ViewController: UIViewController {

var selectedStickerView:StickerView! = nil

var stickerView:StickerView!

override func viewDidLoad() {
super.viewDidLoad()
let configuration = Configuration()
configuration.borderWidth = 2
configuration.buttonSize = CGSize(width: 16, height: 16)
// configuration.buttonSize = CGSize(width: 32, height: 16)

let testView = UIImageView(frame: CGRect.init(x: 0, y: 0, width: 150, height: 100))
testView.backgroundColor = UIColor.red
testView.image = UIImage(named: "image")
let stickerView = StickerView.init(contentView: testView, configuration: configuration)
stickerView = StickerView.init(contentView: testView, configuration: configuration)
stickerView.center = self.view.center
self.view.addSubview(stickerView)

// Do any additional setup after loading the view, typically from a nib.
}

@IBAction func showHideEditView(_ sender: Any) {
stickerView.showEditingHandlers = !stickerView.showEditingHandlers
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
Expand Down
105 changes: 87 additions & 18 deletions Source/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,113 @@ enum ButtonType {
}

enum ButtonPosition{
case top_left,bottom_right,bottom_left,midle_left,midle_bottom
case top_left,bottom_right,bottom_left,midle_left,midle_bottom,top_right
}


struct Button {
var buttonPosition:ButtonPosition!
var buttonType:ButtonType!
var image:UIImage!
var tintColor:UIColor!
var buttonSize:CGSize!
var button:UIButton!
var isOverrideSize:Bool!
private let _defaultbutton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "square.fill")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
return button
}()

init(buttonPosition:ButtonPosition!,
buttonType:ButtonType!,tintColor:UIColor = .black,
image:UIImage = UIImage(systemName: "square.fill")!,buttonSize:CGSize? = nil) {
buttonType:ButtonType!,
button:UIButton? = nil,
isOverrideSize:Bool = false
) {
self.buttonPosition = buttonPosition
self.buttonType = buttonType
self.image = image
self.tintColor = tintColor
self.buttonSize = buttonSize

self.button = button ?? _defaultbutton
self.isOverrideSize = isOverrideSize
}
}

open class Configuration {

public init(){}

var activeButtons:[Button]! = [Button(buttonPosition: .top_left, buttonType: .remove,image: UIImage(systemName: "trash")!),
Button(buttonPosition: .bottom_right, buttonType: .scale,image: UIImage(systemName: "arrow.up.left.and.arrow.down.right")!),
Button(buttonPosition: .bottom_left, buttonType: .rotate,image: UIImage(systemName: "gobackward")!),
Button(buttonPosition: .midle_left, buttonType: .stretch_width,image: UIImage(systemName: "square.fill")!),
Button(buttonPosition: .midle_bottom, buttonType: .stretch_height,image: UIImage(systemName: "square.fill")!)
]
var activeButtons:[Button]! = []
var minimumSize:CGFloat! = 16 * 4
public var insetMarging:CGFloat! = 16
public var boarderColor:UIColor! = .darkGray
public var borderWidth:CGFloat! = 2
public var buttonSize:CGSize! = CGSize(width: 16, height: 16) {
public var buttonSize:CGSize! = CGSize(width: 28, height: 28) {
didSet{
minimumSize = buttonSize.width * 4
}
}

private lazy var _trashButton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "trash")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
buttonDecorator(button)
return button
}()
private lazy var _scaleButton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "arrow.up.left.and.arrow.down.right")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
buttonDecorator(button)
return button
}()

private lazy var _rotateButton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "gobackward")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
buttonDecorator(button)
return button
}()

private lazy var _stretchWidthButton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "square.fill")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
buttonDecorator(button)
return button
}()

private lazy var _stretchHeightButton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "square.fill")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
buttonDecorator(button)
return button
}()
private lazy var _flipImageButton:UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "flip.horizontal.fill")!, for: .normal)
button.frame.size = CGSize(width: 16, height: 16)
buttonDecorator(button)
return button
}()


private func buttonDecorator(_ button:UIButton){
button.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
button.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
button.layer.shadowOpacity = 1.0
button.layer.shadowRadius = 4.0
button.layer.masksToBounds = false
button.layer.cornerRadius = buttonSize.width/2
button.backgroundColor = .white
}

public init(){
activeButtons = [Button(buttonPosition: .top_left, buttonType: .remove,button: _trashButton),
Button(buttonPosition: .bottom_right, buttonType: .scale,button: _scaleButton),
Button(buttonPosition: .bottom_left, buttonType: .rotate,button: _rotateButton),
Button(buttonPosition: .midle_left, buttonType: .stretch_width,button: _stretchWidthButton),
Button(buttonPosition: .midle_bottom, buttonType: .stretch_height,button: _stretchHeightButton),Button(buttonPosition: .top_right, buttonType: .flip,button: _flipImageButton)]
}



}
Loading

0 comments on commit 4c91afe

Please sign in to comment.