From 7e82b21a4ed3bbd5db06161b5907c1a65a8acf93 Mon Sep 17 00:00:00 2001 From: Fedya Skitsko Date: Thu, 10 Apr 2014 16:35:42 +0300 Subject: [PATCH 1/5] Use custom view for TSMessage (model and view) --- .../Example.xcodeproj/project.pbxproj | 20 + .../xcshareddata/Example.xccheckout | 14 +- ExampleProject/Example/TSDemoViewController.h | 4 +- ExampleProject/Example/TSDemoViewController.m | 15 +- ExampleProject/Example/TSMessageCustomItem.h | 25 + ExampleProject/Example/TSMessageCustomItem.m | 34 + ExampleProject/Example/TSMessageCustomView.h | 16 + ExampleProject/Example/TSMessageCustomView.m | 76 + ExampleProject/Example/closeIcon.png | Bin 0 -> 227 bytes ExampleProject/Example/closeIcon@2x.png | Bin 0 -> 420 bytes .../en.lproj/MainStoryboard.storyboard | 15 +- .../TSMessages/TSMessageDefaultItem.h | 1 + .../TSMessages/TSMessageDefaultView.h | 1 + .../BuildHeaders/TSMessages/TSMessageItem.h | 1 + .../Headers/TSMessages/TSMessageDefaultItem.h | 1 + .../Headers/TSMessages/TSMessageDefaultView.h | 1 + .../Pods/Headers/TSMessages/TSMessageItem.h | 1 + .../Pods/Pods.xcodeproj/project.pbxproj | 2468 +++++------------ TSMessages/Classes/TSMessage.h | 50 +- TSMessages/Classes/TSMessage.m | 143 +- TSMessages/Classes/TSMessageDefaultItem.h | 31 + TSMessages/Classes/TSMessageDefaultItem.m | 37 + TSMessages/Classes/TSMessageItem.h | 83 + TSMessages/Classes/TSMessageItem.m | 62 + TSMessages/Views/TSMessageDefaultView.h | 18 + TSMessages/Views/TSMessageDefaultView.m | 134 + TSMessages/Views/TSMessageView.h | 67 +- TSMessages/Views/TSMessageView.m | 636 ++--- 28 files changed, 1708 insertions(+), 2246 deletions(-) create mode 100644 ExampleProject/Example/TSMessageCustomItem.h create mode 100644 ExampleProject/Example/TSMessageCustomItem.m create mode 100644 ExampleProject/Example/TSMessageCustomView.h create mode 100644 ExampleProject/Example/TSMessageCustomView.m create mode 100644 ExampleProject/Example/closeIcon.png create mode 100644 ExampleProject/Example/closeIcon@2x.png create mode 120000 ExampleProject/Pods/BuildHeaders/TSMessages/TSMessageDefaultItem.h create mode 120000 ExampleProject/Pods/BuildHeaders/TSMessages/TSMessageDefaultView.h create mode 120000 ExampleProject/Pods/BuildHeaders/TSMessages/TSMessageItem.h create mode 120000 ExampleProject/Pods/Headers/TSMessages/TSMessageDefaultItem.h create mode 120000 ExampleProject/Pods/Headers/TSMessages/TSMessageDefaultView.h create mode 120000 ExampleProject/Pods/Headers/TSMessages/TSMessageItem.h create mode 100644 TSMessages/Classes/TSMessageDefaultItem.h create mode 100644 TSMessages/Classes/TSMessageDefaultItem.m create mode 100644 TSMessages/Classes/TSMessageItem.h create mode 100644 TSMessages/Classes/TSMessageItem.m create mode 100644 TSMessages/Views/TSMessageDefaultView.h create mode 100644 TSMessages/Views/TSMessageDefaultView.m diff --git a/ExampleProject/Example.xcodeproj/project.pbxproj b/ExampleProject/Example.xcodeproj/project.pbxproj index 8d868b04..52a7f2d9 100644 --- a/ExampleProject/Example.xcodeproj/project.pbxproj +++ b/ExampleProject/Example.xcodeproj/project.pbxproj @@ -8,6 +8,10 @@ /* Begin PBXBuildFile section */ 0C9D527520AF4EAA93E80BC5 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A64AE23935D5499BAF0AC8C1 /* libPods.a */; }; + 4C67F9E218F6C38700021ADD /* closeIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C67F9E018F6C38700021ADD /* closeIcon.png */; }; + 4C67F9E318F6C38700021ADD /* closeIcon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4C67F9E118F6C38700021ADD /* closeIcon@2x.png */; }; + 4CCFEF4318EF06FF00CDFE92 /* TSMessageCustomItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCFEF4218EF06FF00CDFE92 /* TSMessageCustomItem.m */; }; + 4CCFEF4618EF09C100CDFE92 /* TSMessageCustomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCFEF4518EF09C100CDFE92 /* TSMessageCustomView.m */; }; CA0B97051719CD6800E06F84 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA0B97041719CD6800E06F84 /* UIKit.framework */; }; CA0B97071719CD6800E06F84 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA0B97061719CD6800E06F84 /* Foundation.framework */; }; CA0B97091719CD6800E06F84 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CA0B97081719CD6800E06F84 /* CoreGraphics.framework */; }; @@ -23,6 +27,12 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 4C67F9E018F6C38700021ADD /* closeIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = closeIcon.png; sourceTree = ""; }; + 4C67F9E118F6C38700021ADD /* closeIcon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "closeIcon@2x.png"; sourceTree = ""; }; + 4CCFEF4118EF06FF00CDFE92 /* TSMessageCustomItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSMessageCustomItem.h; sourceTree = ""; }; + 4CCFEF4218EF06FF00CDFE92 /* TSMessageCustomItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageCustomItem.m; sourceTree = ""; }; + 4CCFEF4418EF09C100CDFE92 /* TSMessageCustomView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSMessageCustomView.h; sourceTree = ""; }; + 4CCFEF4518EF09C100CDFE92 /* TSMessageCustomView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageCustomView.m; sourceTree = ""; }; 8B33F75B47A447C8B36A0061 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; }; A64AE23935D5499BAF0AC8C1 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; CA0B97011719CD6800E06F84 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -98,6 +108,10 @@ CA0B97261719CD6800E06F84 /* TSDemoViewController.h */, CA0B97271719CD6800E06F84 /* TSDemoViewController.m */, CA0B970B1719CD6800E06F84 /* Supporting Files */, + 4CCFEF4118EF06FF00CDFE92 /* TSMessageCustomItem.h */, + 4CCFEF4218EF06FF00CDFE92 /* TSMessageCustomItem.m */, + 4CCFEF4418EF09C100CDFE92 /* TSMessageCustomView.h */, + 4CCFEF4518EF09C100CDFE92 /* TSMessageCustomView.m */, ); path = Example; sourceTree = ""; @@ -105,6 +119,8 @@ CA0B970B1719CD6800E06F84 /* Supporting Files */ = { isa = PBXGroup; children = ( + 4C67F9E018F6C38700021ADD /* closeIcon.png */, + 4C67F9E118F6C38700021ADD /* closeIcon@2x.png */, CA0B970C1719CD6800E06F84 /* Example-Info.plist */, CA0B970D1719CD6800E06F84 /* InfoPlist.strings */, CA0B97101719CD6800E06F84 /* main.m */, @@ -170,8 +186,10 @@ buildActionMask = 2147483647; files = ( CA0B970F1719CD6800E06F84 /* InfoPlist.strings in Resources */, + 4C67F9E318F6C38700021ADD /* closeIcon@2x.png in Resources */, CA0B97171719CD6800E06F84 /* Default.png in Resources */, CA0B97191719CD6800E06F84 /* Default@2x.png in Resources */, + 4C67F9E218F6C38700021ADD /* closeIcon.png in Resources */, CA0B971B1719CD6800E06F84 /* Default-568h@2x.png in Resources */, CA0B971E1719CD6800E06F84 /* MainStoryboard.storyboard in Resources */, CAA3C9E817C3CD180085E06E /* AlternativeDesign.json in Resources */, @@ -204,6 +222,8 @@ files = ( CA0B97111719CD6800E06F84 /* main.m in Sources */, CA0B97151719CD6800E06F84 /* TSAppDelegate.m in Sources */, + 4CCFEF4618EF09C100CDFE92 /* TSMessageCustomView.m in Sources */, + 4CCFEF4318EF06FF00CDFE92 /* TSMessageCustomItem.m in Sources */, CA0B97281719CD6800E06F84 /* TSDemoViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout b/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout index c8327a4b..5ec51d74 100644 --- a/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout +++ b/ExampleProject/Example.xcworkspace/xcshareddata/Example.xccheckout @@ -5,34 +5,34 @@ IDESourceControlProjectFavoriteDictionaryKey IDESourceControlProjectIdentifier - 78E13C39-DCE2-42E8-B56F-F65483531CDC + DAF402E2-1D5F-4FCC-BC4E-54E674A41828 IDESourceControlProjectName Example IDESourceControlProjectOriginsDictionary - A82D8531-0480-4292-B9CA-F43F680C1C78 - https://github.com/mRs-/TSMessages.git + 2462041E-2250-43D4-B8B0-7C9802F94EB6 + https://github.com/XBeg9/TSMessages.git IDESourceControlProjectPath ExampleProject/Example.xcworkspace IDESourceControlProjectRelativeInstallPathDictionary - A82D8531-0480-4292-B9CA-F43F680C1C78 + 2462041E-2250-43D4-B8B0-7C9802F94EB6 ../.. IDESourceControlProjectURL - https://github.com/mRs-/TSMessages.git + https://github.com/XBeg9/TSMessages.git IDESourceControlProjectVersion 110 IDESourceControlProjectWCCIdentifier - A82D8531-0480-4292-B9CA-F43F680C1C78 + 2462041E-2250-43D4-B8B0-7C9802F94EB6 IDESourceControlProjectWCConfigurations IDESourceControlRepositoryExtensionIdentifierKey public.vcs.git IDESourceControlWCCIdentifierKey - A82D8531-0480-4292-B9CA-F43F680C1C78 + 2462041E-2250-43D4-B8B0-7C9802F94EB6 IDESourceControlWCCName TSMessages diff --git a/ExampleProject/Example/TSDemoViewController.h b/ExampleProject/Example/TSDemoViewController.h index b4a4cdd5..5f4e33fb 100644 --- a/ExampleProject/Example/TSDemoViewController.h +++ b/ExampleProject/Example/TSDemoViewController.h @@ -9,8 +9,7 @@ #import #import "TSMessageView.h" -@interface TSDemoViewController : UIViewController - +@interface TSDemoViewController : UIViewController - (IBAction)didTapError:(id)sender; - (IBAction)didTapWarning:(id)sender; @@ -24,5 +23,6 @@ - (IBAction)didTapText:(id)sender; - (IBAction)didTapCustomDesign:(id)sender; - (IBAction)didTapNavbarHidden:(id)sender; +- (IBAction)didTapCustomView:(id)sender; @end diff --git a/ExampleProject/Example/TSDemoViewController.m b/ExampleProject/Example/TSDemoViewController.m index fd057035..b89ac65a 100644 --- a/ExampleProject/Example/TSDemoViewController.m +++ b/ExampleProject/Example/TSDemoViewController.m @@ -10,6 +10,7 @@ #import "TSDemoViewController.h" #import "TSMessage.h" #import "TSMessageView.h" +#import "TSMessageCustomItem.h" @implementation TSDemoViewController @@ -162,9 +163,16 @@ - (IBAction)didTapCustomDesign:(id)sender } - - - +- (IBAction)didTapCustomView:(id)sender { + TSMessageCustomItem *item = [TSMessageCustomItem itemWithTitle:@"Test" subtitle:@"description" type:TSMessageNotificationTypeSuccess inViewController:self tapHandler:^(TSMessageCustomItem *item) { + NSLog(@"Message did pressed"); + } iconHandler:^(TSMessageCustomItem *item) { + NSLog(@"Icon did pressed"); + } disclosureView:nil disclosureHandler:^(TSMessageCustomItem *item) { + NSLog(@"Disclosure view did pressed"); + }]; + [TSMessage showNotificationMessageWithItem:item]; +} - (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewController { @@ -174,4 +182,5 @@ - (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewControlle - (IBAction)didTapNavbarHidden:(id)sender { self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden; } + @end diff --git a/ExampleProject/Example/TSMessageCustomItem.h b/ExampleProject/Example/TSMessageCustomItem.h new file mode 100644 index 00000000..676303b3 --- /dev/null +++ b/ExampleProject/Example/TSMessageCustomItem.h @@ -0,0 +1,25 @@ +// +// TSMessageCustomItem.h +// Example +// +// Created by Fedya Skitsko on 4/4/14. +// Copyright (c) 2014 Toursprung. All rights reserved. +// + +#import "TSMessageItem.h" + +@interface TSMessageCustomItem : TSMessageItem + +@property (copy, readwrite, nonatomic) void (^disclosureSelectionHandler)(id item); +@property (copy, readwrite, nonatomic) UIView *disclosureView; + ++ (instancetype)itemWithTitle:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)notificationType + inViewController:(UIViewController *)viewController + tapHandler:(void(^)(TSMessageCustomItem *item))tapHandler + iconHandler:(void(^)(TSMessageCustomItem *item))iconHandler + disclosureView:(UIView *)disclosureView + disclosureHandler:(void(^)(TSMessageCustomItem *item))disclosureHandler; + +@end diff --git a/ExampleProject/Example/TSMessageCustomItem.m b/ExampleProject/Example/TSMessageCustomItem.m new file mode 100644 index 00000000..feb6d969 --- /dev/null +++ b/ExampleProject/Example/TSMessageCustomItem.m @@ -0,0 +1,34 @@ +// +// TSMessageCustomItem.m +// Example +// +// Created by Fedya Skitsko on 4/4/14. +// Copyright (c) 2014 Toursprung. All rights reserved. +// + +#import "TSMessageCustomItem.h" +#import "TSMessageCustomView.h" + +@implementation TSMessageCustomItem + ++ (instancetype)itemWithTitle:(NSString *)title + subtitle:(NSString *)subtitle + type:(TSMessageNotificationType)notificationType + inViewController:(UIViewController *)viewController + tapHandler:(void(^)(TSMessageCustomItem *item))tapHandler + iconHandler:(void(^)(TSMessageCustomItem *item))iconHandler + disclosureView:(UIView *)disclosureView + disclosureHandler:(void(^)(TSMessageCustomItem *item))disclosureHandler { + + TSMessageCustomItem *item = [[TSMessageCustomItem alloc] initWithTitle:title subtitle:subtitle image:[UIImage imageNamed:@"closeIcon"] type:notificationType duration:3.0 inViewController:viewController atPosition:TSMessageNotificationPositionBottom canBeDismissedByUser:YES tapHandler:tapHandler iconHandler:iconHandler]; + item.disclosureView = disclosureView; + item.disclosureSelectionHandler = disclosureHandler; + + return item; +} + +- (Class)classForView { + return [TSMessageCustomView class]; +} + +@end diff --git a/ExampleProject/Example/TSMessageCustomView.h b/ExampleProject/Example/TSMessageCustomView.h new file mode 100644 index 00000000..dbeb581b --- /dev/null +++ b/ExampleProject/Example/TSMessageCustomView.h @@ -0,0 +1,16 @@ +// +// TSMessageCustomView.h +// Example +// +// Created by Fedya Skitsko on 4/4/14. +// Copyright (c) 2014 Toursprung. All rights reserved. +// + +#import "TSMessageView.h" +#import "TSMessageCustomItem.h" + +@interface TSMessageCustomView : TSMessageView + +@property (nonatomic, strong) TSMessageCustomItem *item; + +@end \ No newline at end of file diff --git a/ExampleProject/Example/TSMessageCustomView.m b/ExampleProject/Example/TSMessageCustomView.m new file mode 100644 index 00000000..30e22ff3 --- /dev/null +++ b/ExampleProject/Example/TSMessageCustomView.m @@ -0,0 +1,76 @@ +// +// TSMessageCustomView.m +// Example +// +// Created by Fedya Skitsko on 4/4/14. +// Copyright (c) 2014 Toursprung. All rights reserved. +// + +#import "TSMessageCustomView.h" + +@interface TSMessageCustomView() + +@property (nonatomic) UIButton *closeButton; + +@end + +@implementation TSMessageCustomView + +#pragma mark - Setters / Getters + +- (UIButton *)closeButton { + if (!_closeButton) { + _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_closeButton setImage:[UIImage imageNamed:@"closeIcon"] forState:UIControlStateNormal]; + _closeButton.frame = CGRectMake(0, 0, 20, 20); + [_closeButton addTarget:self action:@selector(closeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; + } + return _closeButton; +} + +#pragma mark - Initialization + +- (id)initWithItem:(TSMessageItem *)item +{ + if (self = [super initWithItem:item]) + { + [self setup]; + } + return self; +} + ++ (CGFloat)heightWithItem:(TSMessageCustomItem *)item { + CGFloat calculatedHeight = [super heightWithItem:item]; + + return calculatedHeight; +} + +#pragma mark - Lifecycle + +- (void)setup { + [super setup]; + + [self.iconImageView removeFromSuperview]; + + self.textSpaceLeft = 17.5f; + [self addSubview:self.closeButton]; + self.alpha = 0.9f; +} + +-(void)layoutSubviews { + [super layoutSubviews]; + + _closeButton.frame = CGRectMake(CGRectGetWidth(self.frame) - self.textSpaceLeft - CGRectGetWidth(_closeButton.frame), roundf((CGRectGetHeight(self.frame) - CGRectGetHeight(_closeButton.frame))/2), _closeButton.frame.size.width, _closeButton.frame.size.height); +} + +#pragma mark - Actions + +- (void)closeButtonPressed { + NSLog(@"closeButtonPressed"); + + if (self.item.disclosureSelectionHandler) { + self.item.disclosureSelectionHandler(self.item); + } +} + +@end diff --git a/ExampleProject/Example/closeIcon.png b/ExampleProject/Example/closeIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..42c0b4e6f93224162e1954f037599204f767418d GIT binary patch literal 227 zcmV<90382`P)B>|02vQWUQ&P%`rqp20e{Vl z>Uc=zL4`Ke0NUCztQn`F5ko{%3kVCLcD1gcJ+l~1kC_l=D|~sekkQ$u@4~hTy_LWV d7QwH-fD>4|i{?jHmVy8P002ovPDHLkV1jXGS!)0Q literal 0 HcmV?d00001 diff --git a/ExampleProject/Example/closeIcon@2x.png b/ExampleProject/Example/closeIcon@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..aa0533d18ccd2e1c698ba409edf8ffafc2233456 GIT binary patch literal 420 zcmV;V0bBlwP)gz>u9LJlk#F?LW#*HNpd?|Bq-Ui9u znSoMfp_{}{MQnj2{}N7clDxdKgEFxcvIBQ9Oa%|VDb?O;ArRK=X)XxBy1m?m2H3Di zxWNDx)*IHSfQ9!&HbnL+)_nd9hQ22sgA>w-L8MmvRoP?YsZqi7L>5Dfw&&*>*BEOw zE^}?s2w*g)?GMonKti8*2%I$OK+^CT*O5tzR%b$K9WDsyK}Ccuoh_mG#aa~N^dc?XjSGjk;l+eGvjE^M~ou1O_+KR zVSwmSbN!!@jgh_JaI$(BB&?B;6*=5H+@OHz-MT&8g*}qNxY^5GFfi9nsXf&~t+PQl z^_~h0W?t!#fhH4OWvo9Q(aH#*bqc!u1-u1LcD{nVSn@>TEaF|cX88dr1_9*dIlAuv O0000 - + - + @@ -98,6 +98,15 @@ +