Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CustomView.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
46 changes: 44 additions & 2 deletions CustomView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,20 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Y0j-bi-2ZE" customClass="ProgressCircleView" customModule="CustomView" customModuleProvider="target">
<rect key="frame" x="0.0" y="8" width="414" height="192"/>
<rect key="frame" x="0.0" y="8" width="264" height="192"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Iw5-we-Vcp">
<rect key="frame" x="111" y="86" width="42" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.81568627449999997" green="0.81568627449999997" blue="0.81568627449999997" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Iw5-we-Vcp" firstAttribute="centerY" secondItem="Y0j-bi-2ZE" secondAttribute="centerY" id="6M3-Xq-lCl"/>
<constraint firstItem="Iw5-we-Vcp" firstAttribute="centerX" secondItem="Y0j-bi-2ZE" secondAttribute="centerX" id="jhs-iS-0vD"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="progressColor">
<color key="value" red="1" green="0.2527923882" blue="1" alpha="0.48747859589041098" colorSpace="custom" customColorSpace="sRGB"/>
Expand All @@ -77,12 +89,41 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="17" translatesAutoresizingMaskIntoConstraints="NO" id="vbU-lL-hzq">
<rect key="frame" x="243" y="41.5" width="163" height="117"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xLk-qQ-EgR">
<rect key="frame" x="0.0" y="0.0" width="163" height="50"/>
<color key="backgroundColor" red="0.81568627449999997" green="0.81568627449999997" blue="0.81568627449999997" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="E7K-zJ-rwd"/>
</constraints>
<state key="normal" title="Random Progress Color"/>
<connections>
<action selector="progressColorTap:" destination="5iR-vg-JBg" eventType="touchUpInside" id="Eoj-lc-ReK"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="45I-8M-WeE">
<rect key="frame" x="0.0" y="67" width="163" height="50"/>
<color key="backgroundColor" red="0.81568627449999997" green="0.81568627449999997" blue="0.81568627449999997" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="QcD-W6-zTB"/>
</constraints>
<state key="normal" title="Random Value Color"/>
<connections>
<action selector="targetColorTap:" destination="5iR-vg-JBg" eventType="touchUpInside" id="Y2J-op-w8n"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
<constraints>
<constraint firstItem="Y0j-bi-2ZE" firstAttribute="leading" secondItem="iHX-3l-oVj" secondAttribute="leading" id="2KX-0f-Btl"/>
<constraint firstAttribute="bottom" secondItem="Y0j-bi-2ZE" secondAttribute="bottom" id="AxZ-ua-03i"/>
<constraint firstItem="Y0j-bi-2ZE" firstAttribute="top" secondItem="iHX-3l-oVj" secondAttribute="top" constant="8" id="IUc-71-LnI"/>
<constraint firstAttribute="trailing" secondItem="Y0j-bi-2ZE" secondAttribute="trailing" id="KHw-9u-Hy6"/>
<constraint firstAttribute="trailing" secondItem="Y0j-bi-2ZE" secondAttribute="trailing" constant="150" id="KHw-9u-Hy6"/>
<constraint firstAttribute="trailing" secondItem="vbU-lL-hzq" secondAttribute="trailing" constant="8" id="rgz-Ps-gbo"/>
<constraint firstItem="vbU-lL-hzq" firstAttribute="centerY" secondItem="iHX-3l-oVj" secondAttribute="centerY" id="uAU-Iv-OPR"/>
</constraints>
</tableViewCellContentView>
</tableViewCell>
Expand Down Expand Up @@ -206,6 +247,7 @@
<tabBarItem key="tabBarItem" title="Circle" image="cicle" selectedImage="cicleSelected" id="gtV-i6-qP3"/>
<connections>
<outlet property="progressCircleView" destination="Y0j-bi-2ZE" id="RfR-EA-jIc"/>
<outlet property="progressLabel" destination="Iw5-we-Vcp" id="9ma-oY-E5z"/>
<outlet property="progressSlider" destination="LnG-Y8-C5N" id="F4D-Sf-vHY"/>
<outlet property="targetSlider" destination="g78-nB-pd6" id="B2x-1b-VAU"/>
<outlet property="widthSlider" destination="Q8n-NL-f4d" id="DmN-qb-ZFR"/>
Expand Down
39 changes: 38 additions & 1 deletion CustomView/Controllers/ProgressCircleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ class ProgressCircleViewController: UITableViewController {
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!

@IBOutlet weak var progressLabel: UILabel!

var progress: Float = 0 {
didSet {
progressLabel.text = "\(String(format: "%.2f", progress*100))%"
}
}

override func viewDidLoad() {
super.viewDidLoad()

progress = progressSlider.value
self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value)
self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value)
Expand All @@ -35,10 +43,39 @@ class ProgressCircleViewController: UITableViewController {

@IBAction func progessChange(_ sender: Any) {
self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value)
progress = self.progressSlider.value
}

@IBAction func targetChange(_ sender: Any) {
self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value)
}

@IBAction func progressColorTap(_ sender: Any) {
let color = UIColor.random()
self.progressCircleView?.progressColor = color
self.progressLabel.textColor = color
(sender as! UIButton).backgroundColor = color
}


@IBAction func targetColorTap(_ sender: Any) {
let color = UIColor.random()
self.progressCircleView?.targetColor = color
(sender as! UIButton).backgroundColor = color
}
}

extension CGFloat {
static func random() -> CGFloat {
return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
}

extension UIColor {
static func random() -> UIColor {
return UIColor(red: .random(),
green: .random(),
blue: .random(),
alpha: 1.0)
}
}
12 changes: 10 additions & 2 deletions CustomView/Views/ProgressCircleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ class ProgressCircleView: UIView {
var circleColor:UIColor = UIColor.black

@IBInspectable
var progressColor:UIColor = UIColor.yellow
var progressColor:UIColor = UIColor.yellow {
didSet{
setNeedsDisplay()
}
}

@IBInspectable
var targetColor:UIColor = UIColor.green
var targetColor:UIColor = UIColor.green{
didSet{
setNeedsDisplay()
}
}

// Method that draw the circle, progress and target
override func draw(_ rect: CGRect) {
Expand Down