review notes fixed

This commit is contained in:
Николай Ашанин 2016-09-29 17:51:52 +03:00
parent 2dc2ac0c3b
commit 6f6ff9f3ec
10 changed files with 57 additions and 39 deletions

BIN
LeadKit/.DS_Store vendored

Binary file not shown.

View File

@ -57,6 +57,7 @@
95B39A7E1D9C069B0057BD54 /* UIImage+Text.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A7D1D9C069B0057BD54 /* UIImage+Text.swift */; };
95B39A801D9C09440057BD54 /* UIImage+Cropping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A7F1D9C09440057BD54 /* UIImage+Cropping.swift */; };
95B39A841D9C0C3E0057BD54 /* UIImage+Alpha.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A831D9C0C3E0057BD54 /* UIImage+Alpha.swift */; };
95B39A861D9D51250057BD54 /* String+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B39A851D9D51250057BD54 /* String+Localization.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -123,6 +124,7 @@
95B39A7D1D9C069B0057BD54 /* UIImage+Text.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Text.swift"; sourceTree = "<group>"; };
95B39A7F1D9C09440057BD54 /* UIImage+Cropping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Cropping.swift"; sourceTree = "<group>"; };
95B39A831D9C0C3E0057BD54 /* UIImage+Alpha.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Alpha.swift"; sourceTree = "<group>"; };
95B39A851D9D51250057BD54 /* String+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Localization.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -216,6 +218,7 @@
isa = PBXGroup;
children = (
787783661CA04D4A001CDC9B /* String+SizeCalculation.swift */,
95B39A851D9D51250057BD54 /* String+Localization.swift */,
);
path = String;
sourceTree = "<group>";
@ -575,6 +578,7 @@
78C36F771D80117D00E7EBEA /* UIImage+Transformations.swift in Sources */,
786D78EA1D53C43E006B2CEA /* ApiError.swift in Sources */,
787A071A1D085750009EC97F /* CellsControllerProtocol.swift in Sources */,
95B39A861D9D51250057BD54 /* String+Localization.swift in Sources */,
78C36F7E1D801E3E00E7EBEA /* Double+Rounding.swift in Sources */,
78CFEE551C5C45E500F50370 /* NibNameProtocol.swift in Sources */,
78CFEE561C5C45E500F50370 /* ReuseIdentifierProtocol.swift in Sources */,

View File

@ -0,0 +1,22 @@
//
// String+Localization.swift
// LeadKit
//
// Created by Николай Ашанин on 29.09.16.
// Copyright © 2016 Touch Instinct. All rights reserved.
//
import UIKit
public extension String {
/**
method returns localized string with default comment and self name
- returns: localized string
*/
public func localized() -> String {
return NSLocalizedString(self, comment: "")
}
}

View File

@ -27,7 +27,7 @@ public extension UIImage {
- returns: a copy of the given image, adding an alpha channel if it doesn't already have one.
*/
public func applyAlpha() -> UIImage? {
if hasAlpha() {
guard !hasAlpha() else {
return self
}

View File

@ -32,11 +32,11 @@ public extension UIImage {
- returns: cropped image
*/
public func cropToSquare() -> UIImage? {
let newSize = CGSize(width: size.width * scale, height: size.height * scale)
let shortest = min(newSize.width, newSize.height)
let left: CGFloat = newSize.width > shortest ? (newSize.width-shortest)/2 : 0
let top: CGFloat = newSize.height > shortest ? (newSize.height-shortest)/2 : 0
let rect = CGRect(x: 0, y: 0, width: size.width, height: newSize.height)
let scaledSize = CGSize(width: size.width * scale, height: size.height * scale)
let shortest = min(scaledSize.width, scaledSize.height)
let left: CGFloat = scaledSize.width > shortest ? (scaledSize.width-shortest)/2 : 0
let top: CGFloat = scaledSize.height > shortest ? (scaledSize.height-shortest)/2 : 0
let rect = CGRect(x: 0, y: 0, width: scaledSize.width, height: scaledSize.height)
let insetRect = CGRectInset(rect, left, top)
return crop(insetRect)
}

View File

@ -23,7 +23,8 @@ public extension UIImage {
let colorSpace = CGColorSpaceCreateDeviceRGB()
let colors = gradientColors.map {(color: UIColor) -> AnyObject? in return color.CGColor as AnyObject? } as NSArray
let gradient = CGGradientCreateWithColors(colorSpace, colors, nil)
CGContextDrawLinearGradient(context, gradient,
CGContextDrawLinearGradient(context,
gradient,
CGPoint(x: 0, y: 0),
CGPoint(x: 0, y: size.height),
CGGradientDrawingOptions(rawValue: 0))
@ -79,12 +80,12 @@ public extension UIImage {
public convenience init?(startColor: UIColor,
endColor: UIColor,
radialGradientCenter: CGPoint = CGPoint(x: 0.5, y: 0.5),
radius: Float = 0.5,
radius: CGFloat = 0.5,
size: CGSize = CGSize(width: 100, height: 100)) {
UIGraphicsBeginImageContextWithOptions(size, true, 0)
let numLocations: Int = 2
let locations: [CGFloat] = [0.0, 1.0] as [CGFloat]
let locations: [CGFloat] = [0.0, 1.0]
let startComponents = CGColorGetComponents(startColor.CGColor)
let endComponents = CGColorGetComponents(endColor.CGColor)
@ -104,7 +105,7 @@ public extension UIImage {
// Normalize the 0-1 ranged inputs to the width of the image
let aCenter = CGPoint(x: radialGradientCenter.x * size.width,
y: radialGradientCenter.y * size.height)
let aRadius = CGFloat(min(size.width, size.height)) * CGFloat(radius)
let aRadius = (min(size.width, size.height)) * (radius)
// Draw it
CGContextDrawRadialGradient(UIGraphicsGetCurrentContext(),

View File

@ -15,23 +15,13 @@ public enum UIImageContentMode {
case ScaleToFill, ScaleAspectFit, ScaleAspectFill
}
struct StaticSharedCache {
static var sharedCache: NSCache? = nil
static var onceToken: dispatch_once_t = 0
}
public extension UIImage {
/**
a singleton shared NSURL cache used for images from URL
- returns: shared image cache
*/
private class func sharedCache() -> NSCache {
dispatch_once(&StaticSharedCache.onceToken) {
StaticSharedCache.sharedCache = NSCache()
}
return StaticSharedCache.sharedCache
static var sharedCache: NSCache = {
return NSCache()
}
// MARK: Image From URL
@ -39,23 +29,23 @@ public extension UIImage {
/**
creates a new image from a URL with optional caching.
if cached, the cached image is returned.
otherwise, a place holder is used until the image from web is returned by the closure.
otherwise, a place holder is used until the image from web is returned by the fetchComplete.
- parameter url: The image URL.
- parameter placeholder: The placeholder image.
- parameter shouldCacheImage: Weather or not we should cache the NSURL response (default: true)
- parameter closure: Returns the image from the web the first time is fetched.
- parameter fetchComplete: Returns the image from the web the first time is fetched.
- returns: A new image
*/
public class func imageFromURL(url: String,
placeholder: UIImage,
shouldCacheImage: Bool = true,
closure: (image: UIImage?) -> ()) -> UIImage? {
fetchComplete: (image: UIImage?) -> ()) -> UIImage? {
// From Cache
if shouldCacheImage {
if let image = UIImage.sharedCache().objectForKey(url) as? UIImage {
closure(image: nil)
fetchComplete(image: nil)
return image
}
}
@ -65,7 +55,7 @@ public extension UIImage {
session.dataTaskWithURL(nsURL, completionHandler: { (data, response, error) -> Void in
if error != nil {
dispatch_async(dispatch_get_main_queue()) {
closure(image: nil)
fetchComplete(image: nil)
}
}
if let data = data, image = UIImage(data: data) {
@ -73,7 +63,7 @@ public extension UIImage {
UIImage.sharedCache().setObject(image, forKey: url)
}
dispatch_async(dispatch_get_main_queue()) {
closure(image: image)
fetchComplete(image: image)
}
}
session.finishTasksAndInvalidate()

View File

@ -38,8 +38,8 @@ public extension UIImage {
*/
public func resize(size: CGSize,
contentMode: UIImageContentMode = .ScaleToFill) -> UIImage? {
let horizontalRatio = size.width/size.width
let verticalRatio = size.height/size.height
let horizontalRatio = size.width / size.width
let verticalRatio = size.height / size.height
var ratio: CGFloat = 1
switch contentMode {

View File

@ -58,13 +58,13 @@ public extension UIImage {
CGContextSaveGState(context)
CGContextTranslateCTM(context, rect.minX, rect.minY)
CGContextScaleCTM(context, cornerRadius, cornerRadius)
let fw = rect.size.width / cornerRadius
let fh = rect.size.height / cornerRadius
CGContextMoveToPoint(context, fw, fh/2)
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1)
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1)
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1)
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1)
let roundedWidth = rect.size.width / cornerRadius
let roundedHeight = rect.size.height / cornerRadius
CGContextMoveToPoint(context, roundedWidth, roundedHeight/2)
CGContextAddArcToPoint(context, roundedWidth, roundedHeight, roundedWidth/2, roundedHeight, 1)
CGContextAddArcToPoint(context, 0, roundedHeight, 0, roundedHeight/2, 1)
CGContextAddArcToPoint(context, 0, 0, roundedWidth/2, 0, 1)
CGContextAddArcToPoint(context, roundedWidth, 0, roundedWidth, roundedHeight/2, 1)
CGContextRestoreGState(context)
}
CGContextClosePath(context)

View File

@ -31,12 +31,13 @@ public extension UIImageView {
image = UIImage.imageFromURL(url,
placeholder: placeholder,
shouldCacheImage: shouldCacheImage) { (uploadedImage: UIImage?) in
shouldCacheImage: shouldCacheImage) { [weak self]
(uploadedImage: UIImage?) in
guard let image = uploadedImage else {
return nil
}
self.image = image
self?.image = image
if fadeIn {
let transition = CATransition()
transition.duration = 0.5