Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 25, 2016
0 parents
commit 671dd75
Showing
320 changed files
with
16,352 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Constants.h | ||
// BarButtonItemColor | ||
// | ||
// Created by Magno Urbano on 16/07/15. | ||
// Copyright © 2015 -. All rights reserved. | ||
// Part of the book Troubleshooting Xcode, published by Apress | ||
|
||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface Constants : NSObject | ||
|
||
+ (NSArray *) myConstantArray; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Constants.m | ||
// BarButtonItemColor | ||
// | ||
// Created by Magno Urbano on 16/07/15. | ||
// Copyright © 2015 -. All rights reserved. | ||
// Part of the book Troubleshooting Xcode, published by Apress | ||
|
||
#import "Constants.h" | ||
|
||
@implementation Constants | ||
|
||
|
||
+ (NSArray *) myConstantArray { | ||
// by declaring the static on the .m we guarantee that other | ||
// classes using this one will not make their | ||
// own copy of the static | ||
static NSArray *_myConstantArray = nil; | ||
|
||
@synchronized (_myConstantArray) { | ||
if (_myConstantArray == nil) { | ||
_myConstantArray = @[ /*… your array here … */ ]; | ||
} | ||
return _myConstantArray; | ||
} | ||
} | ||
|
||
|
||
|
||
@end |
18 changes: 18 additions & 0 deletions
18
...endent Rounded Corners/Objective-C/UIView Independent Corners/UIView+IndependentCorners.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// UIView+IndependentCorners.h | ||
// Vacations | ||
// | ||
// Created by Fireball on 11/07/15. | ||
// Copyright (c) 2015 Magno Urbano. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIView (IndependentCorners) | ||
|
||
|
||
- (void)setCorners:(UIRectCorner)corners withRadius:(CGFloat)radius; | ||
|
||
|
||
|
||
@end |
32 changes: 32 additions & 0 deletions
32
...endent Rounded Corners/Objective-C/UIView Independent Corners/UIView+IndependentCorners.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// UIView+IndependentCorners.m | ||
// Vacations | ||
// | ||
// Created by Fireball on 11/07/15. | ||
// Copyright (c) 2015 Magno Urbano. All rights reserved. | ||
// | ||
|
||
#import "UIView+IndependentCorners.h" | ||
|
||
@implementation UIView (IndependentCorners) | ||
|
||
|
||
- (void)setCorners:(UIRectCorner)corners withRadius:(CGFloat)radius | ||
{ | ||
|
||
// UIButton requires this | ||
// [self layer].cornerRadius = 0.0; | ||
|
||
UIBezierPath *shapePath = [UIBezierPath bezierPathWithRoundedRect:[self bounds] | ||
byRoundingCorners:corners | ||
cornerRadii:CGSizeMake(radius, radius)]; | ||
|
||
CAShapeLayer *newCornerLayer = [CAShapeLayer layer]; | ||
newCornerLayer.frame = [self bounds]; | ||
newCornerLayer.path = shapePath.CGPath; | ||
[self layer].mask = newCornerLayer; | ||
|
||
} | ||
|
||
|
||
@end |
27 changes: 27 additions & 0 deletions
27
...dent Rounded Corners/Swift 2.0/UIView Independent Corners/UIView+IndependentCorners.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// UIView+IndependentCorners.swift | ||
// | ||
// | ||
// Created by Fireball on 10/07/15. | ||
// | ||
// | ||
|
||
import UIKit | ||
import QuartzCore | ||
|
||
|
||
extension UIView { | ||
|
||
|
||
func corners(corners: UIRectCorner, radius : CGFloat) { | ||
|
||
let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius)) | ||
|
||
let cornerLayer = CAShapeLayer() | ||
cornerLayer.frame = self.bounds | ||
cornerLayer.path = maskPath.CGPath | ||
layer.mask = cornerLayer | ||
|
||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...iew compatible UIView/Objective-C/NSView compatible with UIView/NSView+CompatibleUIView.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// NSView+CompatibleUIView.h | ||
// MacOBJC | ||
// | ||
// Created by Fireball on 11/07/15. | ||
// Copyright (c) 2015 -. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@interface NSView (CompatibleUIView) | ||
|
||
|
||
- (void)setAlpha:(CGFloat)point; | ||
- (CGFloat)alpha; | ||
|
||
- (void)setCenter:(CGPoint)point; | ||
- (CGPoint)center; | ||
|
||
+(void)fadeOut:(NSView*)viewToDissolve | ||
withDuration:(NSTimeInterval)duration; | ||
|
||
+(void)fadeIn:(NSView*)viewToFadeIn | ||
withDuration:(NSTimeInterval)duration; | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration | ||
animations:(void (^)(void))animations; | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration | ||
animations:(void (^)(void))animations | ||
completion:(void (^)(BOOL | ||
finished))completion; | ||
|
||
|
||
|
||
@end |
99 changes: 99 additions & 0 deletions
99
...iew compatible UIView/Objective-C/NSView compatible with UIView/NSView+CompatibleUIView.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// NSView+CompatibleUIView.m | ||
// MacOBJC | ||
// | ||
// Created by Fireball on 11/07/15. | ||
// Copyright (c) 2015 -. All rights reserved. | ||
// | ||
|
||
#import "NSView+CompatibleUIView.h" | ||
|
||
@implementation NSView (CompatibleUIView) | ||
|
||
|
||
- (void)setAlpha:(CGFloat)point { | ||
[self setAlphaValue:point]; | ||
} | ||
|
||
- (CGFloat)alpha { | ||
return self.alphaValue; | ||
} | ||
|
||
- (void)setCenter:(CGPoint)point { | ||
CGSize size = self.frame.size; | ||
|
||
CGRect newFrame = CGRectZero; | ||
newFrame.size = size; | ||
|
||
CGFloat width = CGRectGetWidth(self.frame); | ||
CGFloat height = CGRectGetHeight(self.frame); | ||
|
||
CGFloat x = floorf(point.x - (width / 2.0f) ); | ||
CGFloat y = floorf(point.y - (height / 2.0f) ); | ||
|
||
newFrame.origin.x = x; | ||
newFrame.origin.y = y; | ||
|
||
[self setFrame:newFrame]; | ||
} | ||
|
||
- (CGPoint)center { | ||
|
||
return CGPointMake(CGRectGetMidX(self.frame), | ||
CGRectGetMidY(self.frame)); | ||
|
||
} | ||
|
||
+(void)fadeOut:(NSView*)viewToDissolve | ||
withDuration:(NSTimeInterval)duration | ||
{ | ||
[NSAnimationContext beginGrouping]; | ||
[[NSAnimationContext currentContext] setDuration:duration]; | ||
[[viewToDissolve animator] setAlphaValue:0.0]; | ||
[NSAnimationContext endGrouping]; | ||
|
||
} | ||
|
||
+(void)fadeIn:(NSView*)viewToFadeIn | ||
withDuration:(NSTimeInterval)duration | ||
{ | ||
[NSAnimationContext beginGrouping]; | ||
[[NSAnimationContext currentContext] setDuration:duration]; | ||
[[viewToFadeIn animator] setAlphaValue:1.0f]; | ||
[NSAnimationContext endGrouping]; | ||
} | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration | ||
animations:(void (^)(void))animations | ||
{ | ||
[NSAnimationContext beginGrouping]; | ||
[[NSAnimationContext currentContext] setDuration:duration]; | ||
animations(); | ||
[NSAnimationContext endGrouping]; | ||
} | ||
|
||
+ (void)animateWithDuration:(NSTimeInterval)duration | ||
animations:(void (^)(void))animations | ||
completion:(void (^)(BOOL finished))completion | ||
{ | ||
[NSAnimationContext beginGrouping]; | ||
[[NSAnimationContext currentContext] setDuration:duration]; | ||
animations(); | ||
[NSAnimationContext endGrouping]; | ||
|
||
if(animations) | ||
{ | ||
id completionBlock = [completion copy]; | ||
[self performSelector:@selector(runEndBlock:) | ||
withObject:completionBlock | ||
afterDelay:duration]; | ||
} | ||
} | ||
|
||
+ (void)runEndBlock:(void (^)(void))completionBlock | ||
{ | ||
completionBlock(); | ||
} | ||
|
||
|
||
@end |
104 changes: 104 additions & 0 deletions
104
...w compatible UIView/Swift 2.0/NSView compatible with UIView/NSVIew+CompatibleUIVIew.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// NSVIew+CompatibleUIVIew.swift | ||
// MacSwift | ||
// | ||
// Created by Fireball on 11/07/15. | ||
// Copyright (c) 2015 -. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
extension NSView { | ||
|
||
typealias AnimationHandler = () -> Void | ||
typealias CompletionHandler = (finished : Bool) -> Void | ||
|
||
|
||
var center:CGPoint { | ||
|
||
get { | ||
let midX = CGRectGetMidX(frame) | ||
let midY = CGRectGetMidY(frame) | ||
|
||
return CGPointMake(midX, midY) | ||
} | ||
|
||
set(newCenter) { | ||
var newFrame = CGRectZero | ||
newFrame.size = frame.size | ||
|
||
let myWidth = CGRectGetWidth(frame) | ||
let myHeight = CGRectGetHeight(frame) | ||
|
||
let x = floor(newCenter.x - (myWidth / 2.0) ) | ||
let y = floor(newCenter.y - (myHeight / 2.0) ) | ||
|
||
newFrame.origin.x = x | ||
newFrame.origin.y = y | ||
|
||
frame = newFrame | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
var alpha : CGFloat { | ||
|
||
get{ | ||
return alphaValue | ||
} | ||
|
||
set(value) { | ||
alphaValue = value | ||
} | ||
|
||
} | ||
|
||
func fadeInWithDuration (duration : NSTimeInterval) { | ||
wantsLayer = true | ||
NSAnimationContext.beginGrouping() | ||
NSAnimationContext.currentContext().duration = duration | ||
animator().alphaValue = 1.0 | ||
NSAnimationContext.endGrouping() | ||
} | ||
|
||
func fadeOutWithDuration (duration : NSTimeInterval) { | ||
wantsLayer = true | ||
NSAnimationContext.beginGrouping() | ||
NSAnimationContext.currentContext().duration = duration | ||
animator().alphaValue = 0.0 | ||
NSAnimationContext.endGrouping() | ||
} | ||
|
||
func animateWithDuration (duration : NSTimeInterval, animations:AnimationHandler) { | ||
wantsLayer = true | ||
NSAnimationContext.runAnimationGroup({ (context: NSAnimationContext) -> Void in | ||
|
||
context.duration = duration | ||
context.allowsImplicitAnimation = true | ||
|
||
animations() | ||
}, completionHandler: { () -> Void in | ||
|
||
}) | ||
} | ||
|
||
|
||
func animateWithDuration (duration : NSTimeInterval, animations:AnimationHandler, completion:CompletionHandler) { | ||
wantsLayer = true | ||
|
||
NSAnimationContext.runAnimationGroup({ (context: NSAnimationContext) -> Void in | ||
|
||
context.duration = duration | ||
context.allowsImplicitAnimation = true | ||
|
||
animations() | ||
}, completionHandler: { () -> Void in | ||
completion(finished:true) | ||
|
||
}) | ||
|
||
} | ||
} |
Oops, something went wrong.