-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed interface like factory style.
- Loading branch information
1 parent
e24ef09
commit f6c1fc1
Showing
8 changed files
with
216 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Sliders.swift | ||
// SummerSlider | ||
// | ||
// Created by derrick on 26/09/2017. | ||
// Copyright © 2017 SuperbDerrick. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct HorizontalSlider: SliderDrawingProtocol , DrawAPIProtocol{ | ||
|
||
var slider: Slider | ||
|
||
init(slider: Slider){ | ||
self.slider = slider | ||
} | ||
|
||
func getDrawingImage(rect : CGRect) -> (UIImage,UIImage) { | ||
|
||
// Basic Setup to make a Inner Rect. | ||
let innerRect = rect.insetBy(dx: Constants.INNER_RECT.X, dy: Constants.INNER_RECT.Y) | ||
UIGraphicsBeginImageContextWithOptions(innerRect.size ,false , 0) | ||
let context = UIGraphicsGetCurrentContext()! | ||
|
||
// Draw Selection Rect. | ||
drawRect(context, innerRect , slider.iSelectedBarColor.cgColor) | ||
|
||
// Make Selection Image. | ||
let selectedSide = UIGraphicsGetImageFromCurrentImageContext() | ||
selectedSide!.resizableImage(withCapInsets: UIEdgeInsets.zero) | ||
|
||
// Draw UNSelection Rect. | ||
drawRect(context, innerRect , slider.iUnSelectedBarColor.cgColor) | ||
|
||
// Make UNSelection Image. | ||
let unSelectedSide = UIGraphicsGetImageFromCurrentImageContext() | ||
unSelectedSide!.resizableImage(withCapInsets: UIEdgeInsets.zero) | ||
|
||
// Draw Selection Image. | ||
selectedSide!.draw(at: CGPoint(x:0,y:0)) | ||
|
||
|
||
// Draw Selection Marks. slider.iMarkColor.cgColor, slider.iMarkPositions, slider.iMarkWidth | ||
drawMarks(context, innerRect, slider.iMarkColor.cgColor , slider.iMarkPositions , slider.iMarkWidth ) | ||
|
||
|
||
let selectedStripSide = UIGraphicsGetImageFromCurrentImageContext()!.resizableImage(withCapInsets: UIEdgeInsets.zero) | ||
|
||
// Draw UNSelection Image. | ||
unSelectedSide!.draw(at: CGPoint(x:0,y:0)) | ||
|
||
|
||
drawMarks(context, innerRect, slider.iMarkColor.cgColor, slider.iMarkPositions, slider.iMarkWidth) | ||
|
||
|
||
let unselectedStripSide = UIGraphicsGetImageFromCurrentImageContext()!.resizableImage(withCapInsets: UIEdgeInsets.zero) | ||
|
||
UIGraphicsEndImageContext() | ||
|
||
return (selectedStripSide,unselectedStripSide) | ||
} | ||
|
||
func drawMarks(_ context: CGContext, _ innerRect: CGRect, _ markColor: CGColor, _ marks: Array<Float>!, _ markWidth: Float) { | ||
|
||
for mark in marks { | ||
context.setLineWidth(CGFloat(markWidth)) | ||
let markWidth = CGFloat(mark) | ||
let postion:CGFloat! = CGFloat((innerRect.width * markWidth ) / Constants.SLIDER.WHOLE_PERCENT) | ||
context.move(to: CGPoint(x: postion, y: innerRect.height / 2 - 5)) | ||
context.addLine(to: CGPoint(x: postion, y: innerRect.height / 2 + 5)) | ||
context.setStrokeColor(markColor) | ||
context.strokePath() | ||
} | ||
|
||
} | ||
|
||
func drawRect(_ context:CGContext ,_ innerRect : CGRect , _ rectColr:CGColor)->Void { | ||
context.setLineCap(CGLineCap.round); | ||
context.setLineWidth(12.0) | ||
context.move(to: CGPoint(x: 6, y: innerRect.height / 2)) | ||
context.addLine(to: CGPoint(x: innerRect.width - 10, y: innerRect.height / 2)) | ||
context.setStrokeColor(rectColr) | ||
context.strokePath() | ||
} | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Slider.swift | ||
// SummerSlider | ||
// | ||
// Created by derrick on 26/09/2017. | ||
// Copyright © 2017 SuperbDerrick. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Slider{ | ||
var iMarkColor : UIColor | ||
var iSelectedBarColor : UIColor | ||
var iUnSelectedBarColor : UIColor | ||
var iMarkWidth : Float | ||
var iMarkPositions : Array<Float> | ||
var iDrawingMode : DrawingMode | ||
var style: SliderStyle | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// SliderDrawingProtocol.swift | ||
// SummerSlider | ||
// | ||
// Created by derrick on 26/09/2017. | ||
// Copyright © 2017 SuperbDerrick. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol SliderDrawingProtocol { | ||
func getDrawingImage(rect : CGRect)->(UIImage,UIImage) | ||
} | ||
|
||
protocol DrawAPIProtocol { | ||
func drawMarks(_ context:CGContext ,_ innerRect : CGRect , _ markColor:CGColor ,_ marks:Array<Float>! ,_ markWidth:Float)->Void | ||
func drawRect(_ context:CGContext ,_ innerRect : CGRect , _ rectColr:CGColor)->Void | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// SliderFactory.swift | ||
// SummerSlider | ||
// | ||
// Created by derrick on 26/09/2017. | ||
// Copyright © 2017 SuperbDerrick. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct SliderFactory{ | ||
static func getSlider(slider: Slider)->SliderDrawingProtocol { | ||
switch slider.style { | ||
case .Horizontal: | ||
return HorizontalSlider(slider: slider) | ||
case .Vertical: | ||
return VerticalSlider(slider: slider) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Sliders.swift | ||
// SummerSlider | ||
// | ||
// Created by derrick on 26/09/2017. | ||
// Copyright © 2017 SuperbDerrick. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
struct VerticalSlider: SliderDrawingProtocol{ | ||
var slider: Slider | ||
|
||
init(slider: Slider){ | ||
self.slider = slider | ||
} | ||
|
||
func getDrawingImage(rect: CGRect) -> (UIImage,UIImage) { | ||
return (UIImage(),UIImage()) | ||
} | ||
|
||
} | ||
|
||
|
||
|