Skip to content

Commit

Permalink
Refactored for a simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
melvitax committed Oct 23, 2014
1 parent 8499e08 commit 7064fba
Show file tree
Hide file tree
Showing 9 changed files with 1,066 additions and 397 deletions.
4 changes: 2 additions & 2 deletions AF+View+Helper.podspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = 'AF+View+Helper'
s.version = '2.0'
s.version = '2.1'
s.platform = :ios
s.license = 'MIT'
s.summary = 'Convenience extension for UIView in Swift.'
s.homepage = 'https://github.com/melvitax/AFViewHelper'
s.author = { 'Melvin Rivera' => 'melvin@allforces.com' }
s.source = { :git => 'https://github.com/melvitax/AFViewHelper.git', :tag => s.version.to_s }
s.description = 'Auto Layout convenience class for UIView in Swift for handling relationships, position, size, borders and shadows.'
s.description = 'Auto Layout convenience class for UIView in Swift for handling AutoLayout, borders and shadows.'
s.source_files = 'AF+View+Helper/*'
s.framework = 'QuartzCore'
s.requires_arc = true
Expand Down
6 changes: 4 additions & 2 deletions AF+View+Helper/AF+Inspectable+View.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//
// RoundedImageView.swift
// Demo AF+Image+Helper
// AF+Inspectable+View.swift
//
// AF-View-Helper: Version 2.1
//
// Created by Melvin Rivera on 7/24/14.
// Copyright (c) 2014 All Forces. All rights reserved.
// https://github.com/melvitax/AFViewHelper
//

import Foundation
Expand Down
647 changes: 414 additions & 233 deletions AF+View+Helper/AF+View+Extension.swift

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// AppDelegate.swift
// Swift Demo UIView+AF+Additions
//
// Created by Melvin Rivera on 7/2/14.
// Copyright (c) 2014 All Forces. All rights reserved.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="14A386a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// ViewController.swift
// Swift Demo UIView+AF+Additions
//
// Created by Melvin Rivera on 7/2/14.
// Copyright (c) 2014 All Forces. All rights reserved.
Expand All @@ -14,106 +13,116 @@ class ViewController: UIViewController {

let redCircle = UIView(autoLayout:true)

override func viewDidLoad()
{
override func viewDidLoad() {

super.viewDidLoad()

view.backgroundColor = UIColor(white: 0.5, alpha: 1)

// Dashed Box
let width = view.smallestSideLength() * 0.8
var dashedBox = UIView(autoLayout:true)
view.addSubview(dashedBox)
let width = view.smallestSideLength() * 0.8
dashedBox.width(width)
dashedBox.pinHeightToWidth()
dashedBox.centerInSuperview(constant: CGSizeMake(0, 100))
dashedBox.backgroundColor = UIColor(white: 1, alpha: 1)
dashedBox.layoutIfNeeded()
dashedBox.borderWithDashPattern([4, 6], borderWidth: 8, borderColor: UIColor.whiteColor(), cornerRadius: 6)
dashedBox.shadow(color: UIColor.blackColor(), offset: CGSize(width: 0, height: 0), radius: 6, opacity: 2, isMasked: false)

dashedBox.backgroundColor = UIColor(white: 1, alpha: 0.5)
dashedBox
.width(width)
.height(to: dashedBox, attribute: .Width)
.center(to:view)
.layoutIfNeeded()
dashedBox
.borderWithDashPattern([2, 6], borderWidth: 4, borderColor: UIColor.whiteColor(), cornerRadius: 6)
.shadow(color: UIColor.blackColor(), offset: CGSize(width: 0, height: 0), radius: 6, opacity: 2, isMasked: false)

// Red Circle
view.addSubview(redCircle)
redCircle.backgroundColor = UIColor.redColor()
redCircle.pinSizeTo(dashedBox, constant: -50)
redCircle.centerInSuperview(constant: CGSize(width: 0, height: -50))
redCircle.layoutIfNeeded()
redCircle
.size(to: dashedBox, constant: CGSize(width: -50, height: -50))
.center(to: view)
.layoutIfNeeded()
redCircle.roundCornersToCircle(borderColor: UIColor.whiteColor(), borderWidth: 12)
redCircle.clipsToBounds = true



// Top Left Square
var topLeftSquare = UIView(autoLayout:true)
redCircle.addSubview(topLeftSquare)
topLeftSquare.backgroundColor = UIColor(white: 0, alpha: 0.3)
topLeftSquare.pin(.Left, to: redCircle, attribute: .Left)
topLeftSquare.pin(.Top, to: redCircle, attribute: .Top)
topLeftSquare.pin(.Width, to: redCircle, attribute: .Width, constant: -10, multiplier: 0.5)
topLeftSquare.pinHeightToWidth()
topLeftSquare.layoutIfNeeded()

topLeftSquare
.left(to: redCircle)
.top(to: redCircle)
.width(to: redCircle, attribute: .Width, constant: 0, multiplier: 0.48)
.height(to: topLeftSquare, attribute: .Width)
.layoutIfNeeded()

// Top Right Square
var topRightSquare = UIView(autoLayout:true)
redCircle.addSubview(topRightSquare)
topRightSquare.pin(.Left, to: redCircle, attribute: .Left)
topRightSquare.pin(.Top, to: redCircle, attribute: .Top)
topRightSquare.pinSizeTo(topLeftSquare)
topRightSquare.backgroundColor = UIColor(white: 0, alpha: 0.3)
topRightSquare.layoutIfNeeded()
topRightSquare
.right(to: redCircle)
.top(to: redCircle)
.size(to: topLeftSquare)
.layoutIfNeeded()


// Bottom Left Square
var bottomLeftSquare = UIView(autoLayout:true)
redCircle.addSubview(bottomLeftSquare)
bottomLeftSquare.pin(.Left, to: redCircle, attribute: .Left)
bottomLeftSquare.pin(.Bottom, to: redCircle, attribute: .Bottom)
bottomLeftSquare.pinSizeTo(topLeftSquare)
bottomLeftSquare.backgroundColor = UIColor(white: 0, alpha: 0.3)
bottomLeftSquare.layoutIfNeeded()
bottomLeftSquare
.left(to: redCircle)
.bottom(to: redCircle)
.size(to: topLeftSquare)
.layoutIfNeeded()


// Bottom Right Square
var bottomRightSquare = UIView(autoLayout:true)
redCircle.addSubview(bottomRightSquare)
bottomRightSquare.pin(.Right, to: redCircle, attribute: .Right)
bottomRightSquare.pin(.Bottom, to: redCircle, attribute: .Bottom)
bottomRightSquare.pinSizeTo(topLeftSquare)
bottomRightSquare.backgroundColor = UIColor(white: 0, alpha: 0.3)
bottomRightSquare.layoutIfNeeded()
bottomRightSquare
.right(to: redCircle)
.bottom(to: redCircle)
.size(to: topLeftSquare)
.layoutIfNeeded()



// Center Circle
var centerCircle = UIView(autoLayout:true)
redCircle.addSubview(centerCircle)
centerCircle.pinSizeTo(topLeftSquare)
centerCircle.centerInSuperview()
centerCircle.backgroundColor = UIColor(white: 1, alpha: 0.7)
centerCircle.layoutIfNeeded()
centerCircle
.size(to: redCircle, constant: CGSize(width: 0, height: 0), multiplier: 0.6)
.center(to: view)
.layoutIfNeeded()
centerCircle.roundCornersToCircle()


// Center Circle Shadow
var redCircleShadow = UIView(autoLayout:true)
view.insertSubview(redCircleShadow, belowSubview: redCircle)
redCircleShadow.pinSizeTo(topLeftSquare)
redCircleShadow.pinCenterTo(redCircle)
redCircleShadow.backgroundColor = UIColor.blackColor()
redCircleShadow.layoutIfNeeded()
redCircleShadow
.size(to: redCircle)
.center(to: redCircle)
.layoutIfNeeded()
redCircleShadow.cornerRadius(redCircleShadow.width()/2)
redCircleShadow.shadow(color: UIColor.blackColor(), offset: CGSize(width: 0, height: 0), radius: 6, opacity: 1, isMasked: false)


// Dots X
let dotsViewX = UIView(autoLayout:true)
view.addSubview(dotsViewX)
dotsViewX.left(0)
dotsViewX.pin(.CenterY, to: view, attribute: .CenterY)
dotsViewX.pin(.Width, to: view, attribute: .Width)
dotsViewX.height(10)
dotsViewX
.left(0)
.centerY(to: view)
.width(to: view)
.height(10)
.layoutIfNeeded()
var dots = [UIView]()
for i in 1..<11 {
var dot = UIView(autoLayout:true)
dot.backgroundColor = UIColor.darkGrayColor()
dot.backgroundColor = UIColor(white: 0.8, alpha: 0.8)
dotsViewX.addSubview(dot)
dot.cornerRadius(5)
dot.clipsToBounds = true
Expand All @@ -126,10 +135,12 @@ class ViewController: UIViewController {
// Dots Y
let dotsViewY = UIView(autoLayout:true)
view.addSubview(dotsViewY)
dotsViewY.top(0)
dotsViewY.pin(.CenterX, to: view, attribute: .CenterX)
dotsViewY.pin(.Height, to: view, attribute: .Height)
dotsViewY.width(10)
dotsViewY
.top(0)
.centerX(to: view)
.height(to: view)
.width(10)
.layoutIfNeeded()
dots = [UIView]()
for i in 1..<11 {
var dot = UIView(autoLayout:true)
Expand Down
Loading

0 comments on commit 7064fba

Please sign in to comment.