Skip to content

Commit

Permalink
Update project settings, more work on project reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
nealyoung committed Sep 23, 2018
1 parent 7a181eb commit 0f2999f
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 174 deletions.
1 change: 1 addition & 0 deletions NYAlertViewController/NYAlertViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "NYAlertViewController.h"

#import "NYAlertView.h"
#import "NYAlertViewButton.h"
#import "NYAlertViewDismissalAnimationController.h"
#import "NYAlertViewPresentationAnimationController.h"
#import "NYAlertViewPresentationController.h"
Expand Down
13 changes: 0 additions & 13 deletions NYAlertViewController/Private/NYAlertView.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, NYAlertViewButtonType) {
NYAlertViewButtonTypeFilled,
NYAlertViewButtonTypeBordered
};

@interface UIButton (BackgroundColor)

- (void)setBackgroundColor:(UIColor *)color forState:(UIControlState)state;

@end

@interface NYAlertViewButton : UIButton

@property (nonatomic) NYAlertViewButtonType type;

@property (nonatomic) CGFloat cornerRadius;

@end

@interface NYAlertView : UIView

@property UILabel *titleLabel;
Expand Down
158 changes: 0 additions & 158 deletions NYAlertViewController/Private/NYAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,164 +56,6 @@ - (UIImage *)imageWithColor:(UIColor *)color {

@end

@implementation NYAlertViewButton

+ (id)buttonWithType:(UIButtonType)buttonType {
return [super buttonWithType:UIButtonTypeCustom];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];

if (self) {
[self commonInit];
}

return self;
}

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];

if (self) {
[self commonInit];
}

return self;
}

- (void)commonInit {
self.layer.rasterizationScale = [[UIScreen mainScreen] scale];
self.layer.shouldRasterize = YES;

self.layer.borderWidth = 1.0f;

self.cornerRadius = 4.0f;
self.clipsToBounds = YES;

[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];

[self tintColorDidChange];
}

- (void)setHidden:(BOOL)hidden {
[super setHidden:hidden];
[self invalidateIntrinsicContentSize];
}

- (void)setEnabled:(BOOL)enabled {
[super setEnabled:enabled];

// if (!enabled) {
// self.backgroundColor = [UIColor lightGrayColor];
// self.layer.borderColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
// } else {
// self.backgroundColor = self.tintColor;
// self.layer.borderColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// }
}

- (void)tintColorDidChange {
[super tintColorDidChange];

if (self.type == NYAlertViewButtonTypeFilled) {
if (self.enabled) {
[self setBackgroundColor:self.tintColor];
}
} else {
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
}

self.layer.borderColor = self.tintColor.CGColor;

[self setNeedsDisplay];
}

- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
}

//- (void)setEnabled:(BOOL)enabled {
// [super setEnabled:enabled];
//
// if (enabled) {
// self.layer.backgroundColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// } else {
// self.layer.backgroundColor = [UIColor lightGrayColor].CGColor;
// [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
// }
//}

//- (void)setType:(NYAlertViewButtonType)type {
// _type = type;
//
// if (type == NYAlertViewButtonTypeBordered) {
// self.layer.backgroundColor = [UIColor clearColor].CGColor;
// [self setTitleColor:self.tintColor forState:UIControlStateNormal];
// } else {
// self.layer.backgroundColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// }
//}

- (CGSize)intrinsicContentSize {
if (self.hidden) {
return CGSizeZero;
}

return CGSizeMake([super intrinsicContentSize].width + 12.0f, 30.0f);
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self setNeedsDisplay];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[self setNeedsDisplay];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];

self.layer.borderColor = self.tintColor.CGColor;

if (self.type == NYAlertViewButtonTypeBordered) {
self.layer.borderWidth = 1.0f;
} else {
self.layer.borderWidth = 0.0f;
}

if (self.state == UIControlStateHighlighted) {
self.layer.backgroundColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
} else {
if (self.type == NYAlertViewButtonTypeBordered) {
self.layer.backgroundColor = nil;
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
} else {
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
}

@end

@interface NYAlertView ()

@property (nonatomic) NSLayoutConstraint *alertBackgroundWidthConstraint;
Expand Down
13 changes: 13 additions & 0 deletions NYAlertViewController/Private/NYAlertViewButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, NYAlertViewButtonType) {
NYAlertViewButtonTypeFilled,
NYAlertViewButtonTypeBordered
};

@interface NYAlertViewButton : UIButton

@property (nonatomic) NYAlertViewButtonType type;
@property (nonatomic) CGFloat cornerRadius;

@end
159 changes: 159 additions & 0 deletions NYAlertViewController/Private/NYAlertViewButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#import "NYAlertViewButton.h"

@implementation NYAlertViewButton

+ (id)buttonWithType:(UIButtonType)buttonType {
return [super buttonWithType:UIButtonTypeCustom];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];

if (self) {
[self commonInit];
}

return self;
}

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];

if (self) {
[self commonInit];
}

return self;
}

- (void)commonInit {
self.layer.rasterizationScale = [[UIScreen mainScreen] scale];
self.layer.shouldRasterize = YES;

self.layer.borderWidth = 1.0f;

self.cornerRadius = 4.0f;
self.clipsToBounds = YES;

[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];

[self tintColorDidChange];
}

- (void)setHidden:(BOOL)hidden {
[super setHidden:hidden];
[self invalidateIntrinsicContentSize];
}

- (void)setEnabled:(BOOL)enabled {
[super setEnabled:enabled];

// if (!enabled) {
// self.backgroundColor = [UIColor lightGrayColor];
// self.layer.borderColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
// } else {
// self.backgroundColor = self.tintColor;
// self.layer.borderColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// }
}

- (void)tintColorDidChange {
[super tintColorDidChange];

if (self.type == NYAlertViewButtonTypeFilled) {
if (self.enabled) {
[self setBackgroundColor:self.tintColor];
}
} else {
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
}

self.layer.borderColor = self.tintColor.CGColor;

[self setNeedsDisplay];
}

- (CGFloat)cornerRadius {
return self.layer.cornerRadius;
}

- (void)setCornerRadius:(CGFloat)cornerRadius {
self.layer.cornerRadius = cornerRadius;
}

//- (void)setEnabled:(BOOL)enabled {
// [super setEnabled:enabled];
//
// if (enabled) {
// self.layer.backgroundColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// } else {
// self.layer.backgroundColor = [UIColor lightGrayColor].CGColor;
// [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
// }
//}

//- (void)setType:(NYAlertViewButtonType)type {
// _type = type;
//
// if (type == NYAlertViewButtonTypeBordered) {
// self.layer.backgroundColor = [UIColor clearColor].CGColor;
// [self setTitleColor:self.tintColor forState:UIControlStateNormal];
// } else {
// self.layer.backgroundColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// }
//}

- (CGSize)intrinsicContentSize {
if (self.hidden) {
return CGSizeZero;
}

return CGSizeMake([super intrinsicContentSize].width + 12.0f, 30.0f);
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self setNeedsDisplay];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
[self setNeedsDisplay];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];

self.layer.borderColor = self.tintColor.CGColor;

if (self.type == NYAlertViewButtonTypeBordered) {
self.layer.borderWidth = 1.0f;
} else {
self.layer.borderWidth = 0.0f;
}

if (self.state == UIControlStateHighlighted) {
self.layer.backgroundColor = self.tintColor.CGColor;
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
} else {
if (self.type == NYAlertViewButtonTypeBordered) {
self.layer.backgroundColor = nil;
[self setTitleColor:self.tintColor forState:UIControlStateNormal];
} else {
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
}

@end
Loading

0 comments on commit 0f2999f

Please sign in to comment.