Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customization for TKAlertCenter alerts #213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/TapkuLibrary/TKAlertCenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
CGRect _alertFrame;
}

@property (strong) UIColor *alertBackgroundColor;
@property (strong) UIFont *alertFont;
@property (strong) UIColor *alertTextColor;

/** Returns the process’s default notification center.
@return The current process’s default notification center, which is used for alert notifications.
*/
Expand Down
55 changes: 51 additions & 4 deletions src/TapkuLibrary/TKAlertCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@

#import "TKAlertCenter.h"
#import "UIView+TKCategory.h"

#ifndef kTKAlertViewBackgroundColor
#define kTKAlertViewBackgroundColor [UIColor colorWithWhite:0 alpha:0.8]
#endif

#ifndef kTKAlertViewFont
#define kTKAlertViewFont [UIFont boldSystemFontOfSize:14]
#endif

#ifndef kTKAlertViewTextColor
#define kTKAlertViewTextColor [UIColor whiteColor]
#endif

#pragma mark -
@interface TKAlertView : UIView {
Expand All @@ -40,6 +51,10 @@ @interface TKAlertView : UIView {
UIImage *_image;
}

@property (strong) UIColor *alertBackgroundColor;
@property (strong) UIFont *alertFont;
@property (strong) UIColor *alertTextColor;

- (id) init;
- (void) setMessageText:(NSString*)str;
- (void) setImage:(UIImage*)image;
Expand All @@ -54,6 +69,9 @@ - (id) init{
if(!(self = [super initWithFrame:CGRectMake(0, 0, 100, 100)])) return nil;
_messageRect = CGRectInset(self.bounds, 10, 10);
self.backgroundColor = [UIColor clearColor];
self.alertBackgroundColor = kTKAlertViewBackgroundColor;
self.alertFont = kTKAlertViewFont;
self.alertTextColor = kTKAlertViewTextColor;
return self;

}
Expand Down Expand Up @@ -81,11 +99,11 @@ - (void) _drawRoundRectangleInRect:(CGRect)rect withRadius:(CGFloat)radius{


- (void) drawRect:(CGRect)rect{
[[UIColor colorWithWhite:0 alpha:0.8] set];
[self.alertBackgroundColor set];
[self _drawRoundRectangleInRect:rect withRadius:10];
[[UIColor whiteColor] set];
[self.alertTextColor set];
[_text drawInRect:_messageRect
withFont:[UIFont boldSystemFontOfSize:14]
withFont:self.alertFont
lineBreakMode:NSLineBreakByWordWrapping
alignment:NSTextAlignmentCenter];

Expand All @@ -100,7 +118,7 @@ - (void) drawRect:(CGRect)rect{
#pragma mark Setter Methods
- (void) adjust{

CGSize s = [_text sizeWithFont:[UIFont boldSystemFontOfSize:14]
CGSize s = [_text sizeWithFont:self.alertFont
constrainedToSize:CGSizeMake(160,200)
lineBreakMode:NSLineBreakByWordWrapping];

Expand Down Expand Up @@ -161,6 +179,35 @@ - (id) init{
return self;
}

-(void)setAlertFont:(UIFont *)alertFont
{
_alertView.alertFont = alertFont;
}

- (UIFont *)alertFont
{
return _alertView.alertFont;
}

-(void)setAlertBackgroundColor:(UIColor *)alertBackgroundColor
{
_alertView.alertBackgroundColor = alertBackgroundColor;
}

- (UIColor *)alertBackgroundColor
{
return _alertView.alertBackgroundColor;
}

-(void)setAlertTextColor:(UIColor *)alertTextColor
{
_alertView.alertTextColor = alertTextColor;
}

- (UIColor *)alertTextColor
{
return _alertView.alertTextColor;
}

#pragma mark Show Alert Message
- (void) showAlerts{
Expand Down