Merge pull request #16 from TouchInstinct/feature/uiimage_extensions
add some useful extensions to UIImage
This commit is contained in:
commit
5326cb1750
|
|
@ -1,3 +1,7 @@
|
|||
# ================
|
||||
# Swift.gitignore
|
||||
# ================
|
||||
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "LeadKit"
|
||||
s.version = "0.0.1"
|
||||
s.version = "0.0.3"
|
||||
s.summary = "iOS framework with a bunch of tools for rapid development"
|
||||
s.homepage = "https://github.com/TouchInstinct/LeadKit"
|
||||
s.license = "Apache License, Version 2.0"
|
||||
|
|
|
|||
|
|
@ -24,13 +24,18 @@
|
|||
786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 786D78EB1D53C46E006B2CEA /* AlamofireManager+Extensions.swift */; };
|
||||
787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */; };
|
||||
787783631CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */; };
|
||||
787783671CA04D4A001CDC9B /* NSString+SizeCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783661CA04D4A001CDC9B /* NSString+SizeCalculation.swift */; };
|
||||
787783671CA04D4A001CDC9B /* String+SizeCalculation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */; };
|
||||
787A071A1D085750009EC97F /* CellsControllerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 787A07191D085750009EC97F /* CellsControllerProtocol.swift */; };
|
||||
788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788EC1591CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift */; };
|
||||
78A74EA91C6B373700FE9724 /* UIView+DefaultNibName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */; };
|
||||
78B0FC7D1C6B2BE200358B64 /* LogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC7C1C6B2BE200358B64 /* LogFormatter.swift */; };
|
||||
78B0FC7F1C6B2C4D00358B64 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC7E1C6B2C4D00358B64 /* Log.swift */; };
|
||||
78B0FC811C6B2CD500358B64 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B0FC801C6B2CD500358B64 /* App.swift */; };
|
||||
78C36F771D80117D00E7EBEA /* UIImage+Transformations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F761D80117D00E7EBEA /* UIImage+Transformations.swift */; };
|
||||
78C36F791D8011FA00E7EBEA /* UIImage+Resize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F781D8011FA00E7EBEA /* UIImage+Resize.swift */; };
|
||||
78C36F7B1D8015ED00E7EBEA /* UIImage+Creation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F7A1D8015ED00E7EBEA /* UIImage+Creation.swift */; };
|
||||
78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F7D1D801E3E00E7EBEA /* Double+Rounding.swift */; };
|
||||
78C36F811D8021DD00E7EBEA /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C36F801D8021DD00E7EBEA /* UIColor+Hex.swift */; };
|
||||
78CFEE2E1C5C456B00F50370 /* LeadKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 78CFEE2D1C5C456B00F50370 /* LeadKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
78CFEE351C5C456B00F50370 /* LeadKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78CFEE2A1C5C456B00F50370 /* LeadKit.framework */; };
|
||||
78CFEE3A1C5C456B00F50370 /* LeadKitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78CFEE391C5C456B00F50370 /* LeadKitTests.swift */; };
|
||||
|
|
@ -76,13 +81,18 @@
|
|||
786D78EB1D53C46E006B2CEA /* AlamofireManager+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AlamofireManager+Extensions.swift"; sourceTree = "<group>"; };
|
||||
787682F91CAD40C200532AB3 /* StaticEstimatedViewHeightProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticEstimatedViewHeightProtocol.swift; sourceTree = "<group>"; };
|
||||
787783621CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSIndexPath+ImmutableIndexPath.swift"; sourceTree = "<group>"; };
|
||||
787783661CA04D4A001CDC9B /* NSString+SizeCalculation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSString+SizeCalculation.swift"; sourceTree = "<group>"; };
|
||||
787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+SizeCalculation.swift"; sourceTree = "<group>"; };
|
||||
787A07191D085750009EC97F /* CellsControllerProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellsControllerProtocol.swift; sourceTree = "<group>"; };
|
||||
788EC1591CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStoryboard+InstantiateViewController.swift"; sourceTree = "<group>"; };
|
||||
78A74EA81C6B373700FE9724 /* UIView+DefaultNibName.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIView+DefaultNibName.swift"; path = "LeadKit/Extensions/UIView/UIView+DefaultNibName.swift"; sourceTree = SOURCE_ROOT; };
|
||||
78B0FC7C1C6B2BE200358B64 /* LogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogFormatter.swift; sourceTree = "<group>"; };
|
||||
78B0FC7E1C6B2C4D00358B64 /* Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
|
||||
78B0FC801C6B2CD500358B64 /* App.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
|
||||
78C36F761D80117D00E7EBEA /* UIImage+Transformations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Transformations.swift"; sourceTree = "<group>"; };
|
||||
78C36F781D8011FA00E7EBEA /* UIImage+Resize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Resize.swift"; sourceTree = "<group>"; };
|
||||
78C36F7A1D8015ED00E7EBEA /* UIImage+Creation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Creation.swift"; sourceTree = "<group>"; };
|
||||
78C36F7D1D801E3E00E7EBEA /* Double+Rounding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Double+Rounding.swift"; sourceTree = "<group>"; };
|
||||
78C36F801D8021DD00E7EBEA /* UIColor+Hex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = "<group>"; };
|
||||
78CFEE2A1C5C456B00F50370 /* LeadKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LeadKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
78CFEE2D1C5C456B00F50370 /* LeadKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LeadKit.h; sourceTree = "<group>"; };
|
||||
78CFEE2F1C5C456B00F50370 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
|
|
@ -190,12 +200,12 @@
|
|||
path = NSIndexPath;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
787783651CA04D14001CDC9B /* NSString */ = {
|
||||
787783651CA04D14001CDC9B /* String */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
787783661CA04D4A001CDC9B /* NSString+SizeCalculation.swift */,
|
||||
787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */,
|
||||
);
|
||||
path = NSString;
|
||||
path = String;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
78A74EAA1C6B401800FE9724 /* Classes */ = {
|
||||
|
|
@ -218,6 +228,22 @@
|
|||
path = Logging;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
78C36F7C1D801E2F00E7EBEA /* Double */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
78C36F7D1D801E3E00E7EBEA /* Double+Rounding.swift */,
|
||||
);
|
||||
path = Double;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
78C36F7F1D8021D100E7EBEA /* UIColor */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
78C36F801D8021DD00E7EBEA /* UIColor+Hex.swift */,
|
||||
);
|
||||
path = UIColor;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
78CFEE201C5C456B00F50370 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
|
@ -263,7 +289,9 @@
|
|||
78CFEE441C5C45E500F50370 /* Extensions */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
787783651CA04D14001CDC9B /* NSString */,
|
||||
78C36F7F1D8021D100E7EBEA /* UIColor */,
|
||||
78C36F7C1D801E2F00E7EBEA /* Double */,
|
||||
787783651CA04D14001CDC9B /* String */,
|
||||
787783611CA03C84001CDC9B /* NSIndexPath */,
|
||||
78E59B2C1C786CD500C6BFE9 /* UIView */,
|
||||
78E59B2B1C786CBF00C6BFE9 /* UITableView */,
|
||||
|
|
@ -324,6 +352,9 @@
|
|||
children = (
|
||||
786A17A01CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift */,
|
||||
7824CA511CFEE6B700D7B132 /* UIImage+RenderTemplate.swift */,
|
||||
78C36F761D80117D00E7EBEA /* UIImage+Transformations.swift */,
|
||||
78C36F781D8011FA00E7EBEA /* UIImage+Resize.swift */,
|
||||
78C36F7A1D8015ED00E7EBEA /* UIImage+Creation.swift */,
|
||||
);
|
||||
path = UIImage;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -506,24 +537,29 @@
|
|||
78B0FC7F1C6B2C4D00358B64 /* Log.swift in Sources */,
|
||||
78CFEE571C5C45E500F50370 /* StaticNibNameProtocol.swift in Sources */,
|
||||
788EC15A1CF64528009CFB6B /* UIStoryboard+InstantiateViewController.swift in Sources */,
|
||||
787783671CA04D4A001CDC9B /* NSString+SizeCalculation.swift in Sources */,
|
||||
787783671CA04D4A001CDC9B /* String+SizeCalculation.swift in Sources */,
|
||||
78011A641D47ABC500EA16A2 /* UIView+DefaultReuseIdentifier.swift in Sources */,
|
||||
78CFEE531C5C45E500F50370 /* UITableView+DequeueCustomCell.swift in Sources */,
|
||||
786D78EC1D53C46E006B2CEA /* AlamofireManager+Extensions.swift in Sources */,
|
||||
78E59B1B1C77470A00C6BFE9 /* ViewsGenerator.swift in Sources */,
|
||||
78B0FC811C6B2CD500358B64 /* App.swift in Sources */,
|
||||
78C36F771D80117D00E7EBEA /* UIImage+Transformations.swift in Sources */,
|
||||
786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */,
|
||||
787A071A1D085750009EC97F /* CellsControllerProtocol.swift in Sources */,
|
||||
78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */,
|
||||
78CFEE551C5C45E500F50370 /* NibNameProtocol.swift in Sources */,
|
||||
78CFEE561C5C45E500F50370 /* ReuseIdentifierProtocol.swift in Sources */,
|
||||
786D78E81D53C378006B2CEA /* AlamofireRequest+Extensions.swift in Sources */,
|
||||
78C36F811D8021DD00E7EBEA /* UIColor+Hex.swift in Sources */,
|
||||
78E59B191C773EE600C6BFE9 /* ObjectsGenerator.swift in Sources */,
|
||||
78CFEE5B1C5C45E500F50370 /* ViewModelProtocol.swift in Sources */,
|
||||
78C36F7B1D8015ED00E7EBEA /* UIImage+Creation.swift in Sources */,
|
||||
7824CA521CFEE6B700D7B132 /* UIImage+RenderTemplate.swift in Sources */,
|
||||
78CFEE5A1C5C45E500F50370 /* ViewHeightProtocol.swift in Sources */,
|
||||
787682FA1CAD40C300532AB3 /* StaticEstimatedViewHeightProtocol.swift in Sources */,
|
||||
78A74EA91C6B373700FE9724 /* UIView+DefaultNibName.swift in Sources */,
|
||||
786A17A11CB8D71D007F9661 /* UIImage+CapInsetsUtils.swift in Sources */,
|
||||
78C36F791D8011FA00E7EBEA /* UIImage+Resize.swift in Sources */,
|
||||
78CFEE581C5C45E500F50370 /* StaticViewHeightProtocol.swift in Sources */,
|
||||
787783631CA03CA0001CDC9B /* NSIndexPath+ImmutableIndexPath.swift in Sources */,
|
||||
78CFEE591C5C45E500F50370 /* StoryboardIdentifierProtocol.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,11 @@ public extension Alamofire.Manager {
|
|||
- returns: Observable with request
|
||||
*/
|
||||
func apiRequest(apiParameters: ApiRequestParameters) -> Observable<Request> {
|
||||
return rx_request(apiParameters.method, apiParameters.url, parameters: apiParameters.parameters)
|
||||
return rx_request(apiParameters.method,
|
||||
apiParameters.url,
|
||||
parameters: apiParameters.parameters,
|
||||
encoding: apiParameters.encoding,
|
||||
headers: apiParameters.headers)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,5 +41,5 @@ public extension Alamofire.Request {
|
|||
|
||||
return rx_responseResult(responseSerializer: mapperSerializer)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
//
|
||||
// Double+Rounding.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 07/09/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Double {
|
||||
|
||||
/**
|
||||
rounds double value 1.7800000004 to 1.78
|
||||
|
||||
- parameter val: value for rounding
|
||||
- parameter persicion: important number of digits after comma
|
||||
|
||||
- returns: rounded value
|
||||
*/
|
||||
public func roundValue(withPersicion persicion: UInt) -> Double {
|
||||
let divider = pow(10.0, Double(persicion - 1))
|
||||
|
||||
return round(self * divider) / divider
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
//
|
||||
// NSString+SizeCAlculation.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Иван Смолин on 21/03/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/**
|
||||
rounds double value 1.7800000004 to 1.78
|
||||
|
||||
- parameter val: value for rounding
|
||||
- parameter persicion: important number of digits after comma
|
||||
|
||||
- returns: rounded value
|
||||
*/
|
||||
private func roundDouble(val: Double, withPersicion persicion: UInt) -> Double {
|
||||
let divider = pow(10.0, Double(persicion - 1))
|
||||
|
||||
return round(val * divider) / divider
|
||||
}
|
||||
|
||||
extension NSString {
|
||||
|
||||
/**
|
||||
method which calculates string height based on given width and character attributes
|
||||
|
||||
- parameter width: maximum width of string
|
||||
- parameter attributes: dictionary with string character attributes
|
||||
|
||||
- returns: string height
|
||||
*/
|
||||
public func heightWith(width: CGFloat, attributes: [String: AnyObject]?) -> CGFloat {
|
||||
return self.boundingRectWithSize(CGSize(width: width, height: CGFloat.max),
|
||||
options: .UsesLineFragmentOrigin,
|
||||
attributes: attributes,
|
||||
context: nil).size.height
|
||||
}
|
||||
|
||||
/**
|
||||
method which calculates required number of lines to fit string with given width and character attributes
|
||||
|
||||
- parameter width: maximum width of string
|
||||
- parameter attributes: dictionary with string character attributes
|
||||
|
||||
- returns: minimum number of lines
|
||||
*/
|
||||
public func numberOfLinesWith(width: CGFloat, attributes: [String: AnyObject]) -> UInt {
|
||||
guard let font = attributes[NSFontAttributeName] as? UIFont else {
|
||||
preconditionFailure("Value for NSFontAttributeName should be defined in attributes")
|
||||
}
|
||||
|
||||
let paragraphStyle = attributes[NSParagraphStyleAttributeName] as? NSParagraphStyle
|
||||
|
||||
let lineHeight = font.lineHeight * (paragraphStyle?.lineHeightMultiple ?? 1.0)
|
||||
|
||||
let lineHeightRounded = roundDouble(Double(lineHeight), withPersicion: 2)
|
||||
|
||||
let height = heightWith(width, attributes: attributes)
|
||||
|
||||
let heightRounded = roundDouble(Double(height), withPersicion: 2)
|
||||
|
||||
let numberOfLines = ceil(heightRounded / lineHeightRounded)
|
||||
|
||||
return UInt(numberOfLines)
|
||||
}
|
||||
|
||||
/**
|
||||
method which calculates string width based on given character attributes
|
||||
|
||||
- parameter attriutes: dictionary with string character attributes
|
||||
|
||||
- returns: string width
|
||||
*/
|
||||
public func widthWith(attriutes: [String: AnyObject]) -> CGFloat {
|
||||
return CGFloat(ceil(Double(sizeWithAttributes(attriutes).width)))
|
||||
}
|
||||
|
||||
/**
|
||||
method which calculates text size based on given character attributes
|
||||
|
||||
- parameter width: maximum width of text
|
||||
- parameter height: maximum height of text
|
||||
- parameter attributes: dictionary with string character attributes
|
||||
|
||||
- returns: text size
|
||||
*/
|
||||
public func sizeWith(maxWidth width: CGFloat = CGFloat.max,
|
||||
maxHeight height: CGFloat = CGFloat.max,
|
||||
attributes: [String: AnyObject]?) -> CGSize {
|
||||
|
||||
return self.boundingRectWithSize(CGSize(width: width, height: height),
|
||||
options: .UsesLineFragmentOrigin,
|
||||
attributes: attributes,
|
||||
context: nil).size
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
//
|
||||
// String+SizeCalculation.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Иван Смолин on 21/03/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
/**
|
||||
* Struct for holding result of string size calculation
|
||||
*/
|
||||
public struct StringSizeCalculationResult {
|
||||
|
||||
public let size: CGSize
|
||||
public let fontLineHeight: CGFloat?
|
||||
|
||||
}
|
||||
|
||||
public extension StringSizeCalculationResult {
|
||||
|
||||
public var height: CGFloat { return size.height }
|
||||
|
||||
public var width: CGFloat { return size.width }
|
||||
|
||||
public var numberOfLines: UInt? {
|
||||
if let lineHeight = fontLineHeight {
|
||||
let lineHeightRounded = Double(lineHeight).roundValue(withPersicion: 2)
|
||||
|
||||
let heightRounded = Double(height).roundValue(withPersicion: 2)
|
||||
|
||||
let numberOfLines = ceil(heightRounded / lineHeightRounded)
|
||||
|
||||
return UInt(numberOfLines)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public extension String {
|
||||
|
||||
/**
|
||||
method which calculates string size based on given character attributes and (optional) max width and height
|
||||
|
||||
- parameter attributes: dictionary with string character attributes
|
||||
- parameter maxWidth: maximum width of text
|
||||
- parameter maxHeight: maximum height of text
|
||||
|
||||
- returns: string size calculation result
|
||||
*/
|
||||
public func size(withAttributes attributes: [String: AnyObject]?,
|
||||
maxWidth: CGFloat = CGFloat.max,
|
||||
maxHeight: CGFloat = CGFloat.max) -> StringSizeCalculationResult {
|
||||
|
||||
let size = self.boundingRectWithSize(CGSize(width: maxWidth, height: maxHeight),
|
||||
options: [.UsesLineFragmentOrigin, .UsesFontLeading],
|
||||
attributes: attributes,
|
||||
context: nil).size
|
||||
|
||||
let fontLineHeight = (attributes?[NSFontAttributeName] as? UIFont)?.lineHeight
|
||||
|
||||
return StringSizeCalculationResult(size: size, fontLineHeight: fontLineHeight)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
//
|
||||
// UIColor+Hex.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 07/09/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public extension UIColor {
|
||||
|
||||
/**
|
||||
The shorthand three-digit hexadecimal representation of color.
|
||||
#RGB defines to the color #RRGGBB.
|
||||
|
||||
- parameter hex3: Three-digit hexadecimal value.
|
||||
- parameter alpha: 0.0 - 1.0. The default is 1.0.
|
||||
|
||||
- returns: new instance with given three-digit hexadecimal value
|
||||
*/
|
||||
public convenience init(hex3: UInt16, alpha: CGFloat = 1) {
|
||||
let red = CGFloat((hex3 & 0xF00) >> 8) / 0xF
|
||||
let green = CGFloat((hex3 & 0x0F0) >> 4) / 0xF
|
||||
let blue = CGFloat((hex3 & 0x00F) >> 0) / 0xF
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
|
||||
/**
|
||||
The shorthand four-digit hexadecimal representation of color with alpha.
|
||||
#RGBA defines to the color #RRGGBBAA.
|
||||
|
||||
- parameter hex4: Four-digit hexadecimal value.
|
||||
|
||||
- returns: new instance with given four-digit hexadecimal value
|
||||
*/
|
||||
public convenience init(hex4: UInt16) {
|
||||
let red = CGFloat((hex4 & 0xF000) >> 12) / 0xF
|
||||
let green = CGFloat((hex4 & 0x0F00) >> 8) / 0xF
|
||||
let blue = CGFloat((hex4 & 0x00F0) >> 4) / 0xF
|
||||
let alpha = CGFloat((hex4 & 0x000F) >> 0) / 0xF
|
||||
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
|
||||
/**
|
||||
The six-digit hexadecimal representation of color of the form #RRGGBB.
|
||||
|
||||
- parameter hex6: Six-digit hexadecimal value.
|
||||
- parameter alpha: alpha: 0.0 - 1.0. The default is 1.0.
|
||||
|
||||
- returns: new instance with given six-digit hexadecimal value
|
||||
*/
|
||||
public convenience init(hex6: UInt32, alpha: CGFloat = 1) {
|
||||
let red = CGFloat((hex6 & 0xFF0000) >> 16) / 0xFF
|
||||
let green = CGFloat((hex6 & 0x00FF00) >> 8) / 0xFF
|
||||
let blue = CGFloat((hex6 & 0x0000FF) >> 0) / 0xFF
|
||||
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
|
||||
/**
|
||||
The six-digit hexadecimal representation of color with alpha of the form #RRGGBBAA.
|
||||
|
||||
- parameter hex8: Eight-digit hexadecimal value.
|
||||
|
||||
- returns: new instance with given eight-digit hexadecimal value
|
||||
*/
|
||||
public convenience init(hex8: UInt32) {
|
||||
let red = CGFloat((hex8 & 0xFF000000) >> 24) / 0xFF
|
||||
let green = CGFloat((hex8 & 0x00FF0000) >> 16) / 0xFF
|
||||
let blue = CGFloat((hex8 & 0x0000FF00) >> 8) / 0xFF
|
||||
let alpha = CGFloat((hex8 & 0x000000FF) >> 0) / 0xFF
|
||||
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
convenience failable initializer which creates an instance with given hex color values if string has a correct format
|
||||
|
||||
- parameter hexString: hex string with red green and blue values (can have `#` sign)
|
||||
- parameter alpha: alpha component used if not given in hexString
|
||||
|
||||
- returns: new instance with given hex color or nil if hexString is incorrect
|
||||
*/
|
||||
public convenience init?(hexString: String, alpha: CGFloat = 1) {
|
||||
let hexStr = hexString.hasPrefix("#") ? hexString.substringFromIndex(hexString.startIndex.advancedBy(1)) : hexString
|
||||
|
||||
let charactersCount = hexStr.characters.count
|
||||
|
||||
switch charactersCount {
|
||||
case 3, 4:
|
||||
if let hex = UInt16(hexStr, radix: 16) {
|
||||
if charactersCount == 3 {
|
||||
self.init(hex3: hex, alpha: alpha)
|
||||
} else {
|
||||
self.init(hex4: hex)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
case 6, 8:
|
||||
if let hex = UInt32(hexStr, radix: 16) {
|
||||
if charactersCount == 6 {
|
||||
self.init(hex6: hex, alpha: alpha)
|
||||
} else {
|
||||
self.init(hex8: hex)
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,26 +8,7 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
extension UIImage {
|
||||
|
||||
/**
|
||||
method which render current UIImage for specific size and return new UIImage
|
||||
|
||||
- parameter size: size of new rendered image
|
||||
|
||||
- returns: new rendered UIImage
|
||||
*/
|
||||
public func renderWithSize(size: CGSize) -> UIImage {
|
||||
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
||||
|
||||
self.drawInRect(CGRect(origin: CGPoint.zero, size: size))
|
||||
|
||||
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
|
||||
|
||||
UIGraphicsEndImageContext()
|
||||
|
||||
return resizedImage
|
||||
}
|
||||
public extension UIImage {
|
||||
|
||||
/**
|
||||
this method tries to find requested image with specific parameters in cache, and if doesn't exists - create it
|
||||
|
|
@ -81,7 +62,7 @@ extension UIImage {
|
|||
right: assetsInsetsForScale.right / scale)
|
||||
|
||||
|
||||
return self.fetchOrCreateImageWithName(name, size: size, capInsets: capInsetsForScale, cache: cache)
|
||||
return fetchOrCreateImageWithName(name, size: size, capInsets: capInsetsForScale, cache: cache)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// UIImage+Creation.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 07/09/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public extension UIImage {
|
||||
|
||||
/**
|
||||
method which creates new UIImage instance filled by given color
|
||||
|
||||
- parameter color: color to fill
|
||||
- parameter size: size of new image
|
||||
- parameter opaque: a flag indicating whether the bitmap is opaque (default: False)
|
||||
- parameter scale: screen scale (default: 0 (pick a device scale))
|
||||
|
||||
- returns: new instanse of UIImage with given size and color
|
||||
*/
|
||||
public static func imageWith(color: UIColor, size: CGSize, opaque: Bool = false, scale: CGFloat = 0) -> UIImage {
|
||||
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
|
||||
|
||||
defer { UIGraphicsEndImageContext() }
|
||||
|
||||
let context = UIGraphicsGetCurrentContext()
|
||||
|
||||
CGContextSetFillColorWithColor(context, color.CGColor)
|
||||
CGContextFillRect(context, CGRect(origin: CGPoint.zero, size: size))
|
||||
|
||||
return UIGraphicsGetImageFromCurrentImageContext()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,12 +14,14 @@ public extension UIImage {
|
|||
method which render current template UIImage into new image using given color
|
||||
|
||||
- parameter color: color which used to fill template image
|
||||
- parameter opaque: a flag indicating whether the bitmap is opaque
|
||||
- parameter opaque: a flag indicating whether the bitmap is opaque (default: False)
|
||||
|
||||
- returns: new UIImage rendered with given color
|
||||
*/
|
||||
public func renderTemplateWithColor(color: UIColor, opaque: Bool = false) -> UIImage {
|
||||
UIGraphicsBeginImageContextWithOptions(size, opaque, 0.0)
|
||||
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
|
||||
|
||||
defer { UIGraphicsEndImageContext() }
|
||||
|
||||
let ctx = UIGraphicsGetCurrentContext()
|
||||
|
||||
|
|
@ -38,11 +40,7 @@ public extension UIImage {
|
|||
CGContextSetBlendMode(ctx, .Multiply)
|
||||
CGContextDrawImage(ctx, imageRect, CGImage)
|
||||
|
||||
let newImage = UIGraphicsGetImageFromCurrentImageContext()
|
||||
|
||||
UIGraphicsEndImageContext()
|
||||
|
||||
return newImage
|
||||
return UIGraphicsGetImageFromCurrentImageContext()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// UIImage+Resize.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 07/09/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public extension UIImage {
|
||||
|
||||
/**
|
||||
method which render current UIImage for specific size and return new UIImage
|
||||
|
||||
- parameter size: size of new image
|
||||
- parameter opaque: a flag indicating whether the bitmap is opaque (default: False)
|
||||
|
||||
- returns: new instance of UIImage rendered with given size
|
||||
*/
|
||||
public func renderWithSize(size: CGSize, opaque: Bool = false) -> UIImage {
|
||||
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
|
||||
|
||||
defer { UIGraphicsEndImageContext() }
|
||||
|
||||
drawInRect(CGRect(origin: CGPoint.zero, size: size))
|
||||
|
||||
return UIGraphicsGetImageFromCurrentImageContext()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// UIImage+Transformations.swift
|
||||
// LeadKit
|
||||
//
|
||||
// Created by Ivan Smolin on 07/09/16.
|
||||
// Copyright © 2016 Touch Instinct. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public extension UIImage {
|
||||
|
||||
/**
|
||||
method which creates new UIImage from current with rounded corners
|
||||
|
||||
- parameter radius: corners radius
|
||||
- parameter opaque: a flag indicating whether the bitmap is opaque (default: False)
|
||||
|
||||
- returns: new UIImage instance rendered with given radius
|
||||
*/
|
||||
public func roundedImage(withRadius radius: CGFloat, opaque: Bool = false) -> UIImage {
|
||||
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
|
||||
|
||||
defer { UIGraphicsEndImageContext() }
|
||||
|
||||
let imageRect = CGRect(origin: CGPoint.zero, size: size)
|
||||
|
||||
UIBezierPath(roundedRect: imageRect, cornerRadius: radius).addClip()
|
||||
|
||||
drawInRect(imageRect)
|
||||
|
||||
return UIGraphicsGetImageFromCurrentImageContext()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.1</string>
|
||||
<string>0.0.3</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
|
|
|||
|
|
@ -18,5 +18,20 @@ public struct ApiRequestParameters {
|
|||
let method: Alamofire.Method
|
||||
let url: URLStringConvertible
|
||||
let parameters: [String: AnyObject]?
|
||||
let encoding: ParameterEncoding
|
||||
let headers: [String: String]?
|
||||
|
||||
public init(method: Alamofire.Method,
|
||||
url: URLStringConvertible,
|
||||
parameters: [String: AnyObject]? = nil,
|
||||
encoding: ParameterEncoding = .URL,
|
||||
headers: [String: String]? = nil) {
|
||||
|
||||
self.method = method
|
||||
self.url = url
|
||||
self.parameters = parameters
|
||||
self.encoding = encoding
|
||||
self.headers = headers
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue