TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2015 |
SPMSupports SPM | ✗ |
Maintained by Cem Olcay.
UIKit toolset for quick prototyping and rapid development
convenience init (x: CGFloat,
y: CGFloat,
w: CGFloat,
h: CGFloat)
var x: CGFloat {
get {
return self.frame.origin.x
} set (value) {
self.frame = CGRect (x: value, y: self.y, width: self.w, height: self.h)
}
}
var y: CGFloat {
get {
return self.frame.origin.y
} set (value) {
self.frame = CGRect (x: self.x, y: value, width: self.w, height: self.h)
}
}
var w: CGFloat {
get {
return self.frame.size.width
} set (value) {
self.frame = CGRect (x: self.x, y: self.y, width: value, height: self.h)
}
}
var h: CGFloat {
get {
return self.frame.size.height
} set (value) {
self.frame = CGRect (x: self.x, y: self.y, width: self.w, height: value)
}
}
var position: CGPoint {
get {
return self.frame.origin
} set (value) {
self.frame = CGRect (origin: value, size: self.frame.size)
}
}
var size: CGSize {
get {
return self.frame.size
} set (value) {
self.frame = CGRect (origin: self.frame.origin, size: size)
}
}
var left: CGFloat {
get {
return self.x
} set (value) {
self.x = value
}
}
var right: CGFloat {
get {
return self.x + self.w
} set (value) {
self.x = value - self.w
}
}
var top: CGFloat {
get {
return self.y
} set (value) {
self.y = value
}
}
var bottom: CGFloat {
get {
return self.y + self.h
} set (value) {
self.y = value - self.h
}
}
func leftWithOffset (offset: CGFloat) -> CGFloat
func rightWithOffset (offset: CGFloat) -> CGFloat
func topWithOffset (offset: CGFloat) -> CGFloat
func botttomWithOffset (offset: CGFloat) -> CGFloat
enum AnchorPosition: CGPoint {
case TopLeft = "{0, 0}"
case TopCenter = "{0.5, 0}"
case TopRight = "{1, 0}"
case MidLeft = "{0, 0.5}"
case MidCenter = "{0.5, 0.5}"
case MidRight = "{1, 0.5}"
case BottomLeft = "{0, 1}"
case BottomCenter = "{0.5, 1}"
case BottomRight = "{1, 1}"
}
func setAnchorPosition (anchorPosition: AnchorPosition)
Adding shadow
func addShadow (offset: CGSize,
radius: CGFloat,
color: UIColor,
opacity: Float)
Adding borders
func addBorder (width: CGFloat,
color: UIColor)
Setting corner radius of borders
func setCornerRadius (radius: CGFloat)
Adding stroke to borders
func drawStroke (width: CGFloat,
color: UIColor)
Circle Drawing
func drawCircle (fillColor: UIColor,
strokeColor: UIColor,
strokeWidth: CGFloat)
Arc Drawing
func drawArc (from: CGFloat,
to: CGFloat,
clockwise: Bool,
width: CGFloat,
fillColor: UIColor,
strokeColor: UIColor,
lineCap: String)
Rotation
func setRotationX (x: CGFloat)
func setRotationY (y: CGFloat)
func setRotationZ (z: CGFloat)
func setRotation (x: CGFloat,
y: CGFloat,
z: CGFloat)
Scale
func setScale (x: CGFloat,
y: CGFloat)
Constants
let UIViewAnimationDuration: NSTimeInterval = 1
let UIViewAnimationSpringDamping: CGFloat = 0.5
let UIViewAnimationSpringVelocity: CGFloat = 0.5
Animation Mehtods
func animate (animations: (()->Void)!,
completion: ((Bool)->Void)? = nil)
func spring (animations: (()->Void)!,
completion: ((Bool)->Void)? = nil)
Tap
func addTapGesture (tapNumber: NSInteger,
target: AnyObject, action: Selector)
Swipe
func addSwipeGesture (
direction: UISwipeGestureRecognizerDirection,
numberOfTouches: Int,
target: AnyObject,
action: Selector)
Pan
func addPanGesture (target: AnyObject,
action: Selector)
Top
var top: CGFloat {
get {
if let nav = self.navigationController {
if nav.navigationBarHidden {
return view.top
} else {
return nav.navigationBar.bottom
}
} else {
return view.top
}
}
}
Bottom
var bottom: CGFloat {
get {
if let tab = tabBarController {
if tab.tabBar.hidden {
return view.bottom
} else {
return tab.tabBar.top
}
} else {
return view.bottom
}
}
}
var applicationFrame: CGRect {
get {
return CGRect (x: view.x, y: top, width: view.w, height: bottom - top)
}
}
var navigationBar: UINavigationBar? {
get {
return navigationController?.navigationBar
}
}
Get Navigation bar height of device
var navigationBarHeight: CGFloat {
get {
if let nav = self.navigationController {
return nav.navigationBar.h
}
return 0
}
}
Get or set navigation bar color
var navigationBarColor: UIColor? {
get {
return navigationController?.navigationBar.tintColor
} set (value) {
navigationController?.navigationBar.barTintColor = value
}
}
AttributedStrings
property for accessing, adding or updating attributedText of label private var UILabelAttributedStringArray: UInt8 = 0
var attributedStrings: [NSAttributedString]? {
get {
return objc_getAssociatedObject(self, &UILabelAttributedStringArray) as? [NSAttributedString]
} set (value) {
objc_setAssociatedObject(self, &UILabelAttributedStringArray, value, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC))
}
}
Adding
func addAttributedString (text: String,
color: UIColor,
font: UIFont)
func addAttributedString (attributedString: NSAttributedString)
Updating
func updateAttributedStringAtIndex (index: Int,
attributedString: NSAttributedString)
func updateAttributedStringAtIndex (index: Int,
newText: String)
func getEstimatedHeight () -> CGFloat
func fitHeight ()
subscript (i: Int) -> String {
return String(Array(self)[i])
}
enum
s for easily create UIFont
s enum FontType: String
enum FontName: String
class func Font (name: FontName, type: FontType, size: CGFloat) -> UIFont
Even customise it for specific font
class func HelveticaNeue (type: FontType, size: CGFloat) -> UIFont
Print all family of font on single line
class func PrintFontFamily (font: FontName)
class func randomColor () -> UIColor
class func RGBColor (r: CGFloat,
g: CGFloat,
b: CGFloat) -> UIColor
class func RGBAColor (r: CGFloat,
g: CGFloat,
b: CGFloat,
a: CGFloat) -> UIColor
Calculate possible aspect width for height
func aspectWidthForHeight (height: CGFloat) -> CGFloat
Calculate possible aspect height for width
func aspectHeightForWidth (width: CGFloat) -> CGFloat
Resize image based on its width (auto calculates height and keeps aspect ratio)
func aspectResizeWithWidth (width: CGFloat) -> UIImage
Resize image based on its height (auto calculates width and keeps aspect ratio)
func aspectResizeWithHeight (height: CGFloat) -> UIImage
CGPoint
s func + (left: CGPoint, right: CGPoint) -> CGPoint
func - (left: CGPoint, right: CGPoint) -> CGPoint
StringLiteralConvertable
implementation public init(stringLiteral value: StringLiteralType)
public init(extendedGraphemeClusterLiteral value: StringLiteralType)
public init(unicodeScalarLiteral value: StringLiteralType) {
self = CGPointFromString(value)
CGSize
s func + (left: CGSize, right: CGSize) -> CGSize
func - (left: CGSize, right: CGSize) -> CGSize
Screen Width
var ScreenWidth: CGFloat {
get {
return UIScreen.mainScreen().bounds.size.width
}
}
Screen Height
var ScreenHeight: CGFloat {
get {
return UIScreen.mainScreen().bounds.size.height
}
}
Status bar height
var StatusBarHeight: CGFloat {
get {
return UIApplication.sharedApplication().statusBarFrame.height
}
}
func degreesToRadians (angle: CGFloat) -> CGFloat
Convert [min, max] to [0, 1]
func normalizeValue (value: CGFloat,
min: CGFloat,
max: CGFloat) -> CGFloat
Convert [0, 1] to to [min, max]
func convertNormalizedValue (value: CGFloat,
min: CGFloat,
max: CGFloat) -> CGFloat
func alert (title: String,
message: String,
cancelAction: ((UIAlertAction!)->Void)? = nil,
okAction: ((UIAlertAction!)->Void)? = nil) -> UIAlertController
func barButtonItem (imageName: String,
action: (AnyObject)->()) -> UIBarButtonItem
func barButtonItem (title: String,
color: UIColor,
action: (AnyObject)->()) -> UIBarButtonItem
UIButton
with actionBlock:
var actionBlock: ((sender: BlockButton) -> ())? {
didSet {
self.addTarget(self, action: "action:", forControlEvents: UIControlEvents.TouchUpInside)
}
}
func action (sender: BlockButton) {
actionBlock! (sender: sender)
}
UIWebView
with block based actions instead of UIWebViewDelegate
var didStartLoad: ((NSURLRequest) -> ())?
var didFinishLoad: ((NSURLRequest) -> ())?
var didFailLoad: ((NSURLRequest, NSError) -> ())?
var shouldStartLoadingRequest: ((NSURLRequest) -> (Bool))?