diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..d90ae2f Binary files /dev/null and b/.DS_Store differ diff --git a/JTAlertView Example/JTAlertView Example.xcodeproj/project.pbxproj b/JTAlertView Example/JTAlertView Example.xcodeproj/project.pbxproj index a7268ff..7c3a017 100644 --- a/JTAlertView Example/JTAlertView Example.xcodeproj/project.pbxproj +++ b/JTAlertView Example/JTAlertView Example.xcodeproj/project.pbxproj @@ -177,7 +177,7 @@ 3BD1B19E1B2CBE7600621F68 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0630; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Jakub Truhlar"; TargetAttributes = { 3BD1B1A51B2CBE7600621F68 = { @@ -291,14 +291,17 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -334,8 +337,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -364,6 +369,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "JTAlertView Example/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jakubtruhlar.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -374,6 +380,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "JTAlertView Example/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jakubtruhlar.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -392,6 +399,7 @@ ); INFOPLIST_FILE = "JTAlertView ExampleTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jakubtruhlar.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JTAlertView Example.app/JTAlertView Example"; }; @@ -407,6 +415,7 @@ ); INFOPLIST_FILE = "JTAlertView ExampleTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.jakubtruhlar.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/JTAlertView Example.app/JTAlertView Example"; }; diff --git a/JTAlertView Example/JTAlertView Example/Info.plist b/JTAlertView Example/JTAlertView Example/Info.plist index d532dfe..8a1e9be 100644 --- a/JTAlertView Example/JTAlertView Example/Info.plist +++ b/JTAlertView Example/JTAlertView Example/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.jakubtruhlar.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/JTAlertView Example/JTAlertView ExampleTests/Info.plist b/JTAlertView Example/JTAlertView ExampleTests/Info.plist index f082bc0..ba72822 100644 --- a/JTAlertView Example/JTAlertView ExampleTests/Info.plist +++ b/JTAlertView Example/JTAlertView ExampleTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.jakubtruhlar.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/JTAlertView/JTAlertView.h b/JTAlertView/JTAlertView.h index 5f67ac9..bdeaee2 100644 --- a/JTAlertView/JTAlertView.h +++ b/JTAlertView/JTAlertView.h @@ -7,6 +7,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @interface JTAlertView : UIView /** In Cancel and Destructive case JTAlertView will try to use bold version of your font (Must be in format FontName-Bold) */ @@ -16,6 +18,8 @@ typedef NS_ENUM(NSInteger, JTAlertViewStyle) { JTAlertViewStyleDestructive }; +typedef void (^JTAlertViewStyling)(UIButton *btn); + // Public properties /** Size of the alertView. Default is 240.0, 290.0. */ @property (nonatomic, assign) CGSize size; @@ -29,6 +33,9 @@ typedef NS_ENUM(NSInteger, JTAlertViewStyle) { /** Image overlay. Default overlay is gray with half alpha. */ @property (nonatomic, strong) UIColor *overlayColor; +/** Button separator color. Default is 97% white. */ +@property (nonatomic, strong) UIColor *separatorColor; + /** Font applied on title and alertView buttons. AlertView buttons will ignore this font's size but not the style (In case you want to setup custom font for your buttons, use font parameter in method instead). Default is Helvetica Neue Medium with 21.0 size. */ @property (nonatomic, strong) UIFont *font; @@ -42,20 +49,23 @@ typedef NS_ENUM(NSInteger, JTAlertViewStyle) { @property (nonatomic, assign, getter=isBackgroundShadow) bool backgroundShadow; // Initializers -+ (instancetype)alertWithTitle:(NSString *)titleText andImage:(UIImage *)image; -- (instancetype)initWithTitle:(NSString *)titleText andImage:(UIImage *)image; ++ (instancetype)alertWithTitle:(NSString * _Nullable)titleText andImage:(UIImage * _Nullable)image; +- (instancetype)initWithTitle:(NSString * _Nullable)titleText andImage:(UIImage * _Nullable)image; // Buttons - (void)addButtonWithTitle:(NSString *)titleText action:(void (^)(JTAlertView *alertView))action; - (void)addButtonWithTitle:(NSString *)titleText style:(JTAlertViewStyle)style action:(void (^)(JTAlertView *alertView))action; - (void)addButtonWithTitle:(NSString *)titleText style:(JTAlertViewStyle)style forControlEvents:(UIControlEvents)controlEvents action:(void (^)(JTAlertView *alertView))action; -- (void)addButtonWithTitle:(NSString *)titleText font:(UIFont *)font style:(JTAlertViewStyle)style forControlEvents:(UIControlEvents)controlEvents action:(void (^)(JTAlertView *alertView))action; +- (void)addButtonWithTitle:(NSString *)titleText font:(UIFont * _Nullable)font style:(JTAlertViewStyle)style forControlEvents:(UIControlEvents)controlEvents action:(void (^)(JTAlertView *alertView))action; + +/** Designated method to adda a button. Provide a styling block to update custom styling to provided button, overriding default JTAlertViewStyle parameter and font. */ +- (void)addButtonWithTitle:(NSString *)titleText styling:(JTAlertViewStyling _Nullable)styling forControlEvents:(UIControlEvents)controlEvents action:(void (^)(JTAlertView *alertView))action; // Displaying - (void)show; -- (void)showInSuperview:(UIView *)superView withCompletion:(void (^)())completion animated:(bool)animated; +- (void)showInSuperview:(UIView *)superView withCompletion:(void (^ _Nullable)())completion animated:(bool)animated; - (void)hide; -- (void)hideWithCompletion:(void (^)())completion animated:(bool)animated; +- (void)hideWithCompletion:( void (^ _Nullable )())completion animated:(bool)animated; - (void)hideWithDelay:(NSTimeInterval)delay animated:(bool)animated; @end @@ -69,3 +79,5 @@ typedef void (^ActionBlock)(JTAlertView *alertView); - (void)handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock)action; @end + +NS_ASSUME_NONNULL_END diff --git a/JTAlertView/JTAlertView.m b/JTAlertView/JTAlertView.m index 7cb4e3b..c0155c0 100644 --- a/JTAlertView/JTAlertView.m +++ b/JTAlertView/JTAlertView.m @@ -76,12 +76,10 @@ + (instancetype)alertWithTitle:(NSString *)titleText andImage:(UIImage *)image { #pragma mark - Buttons handle - (void)addButtonWithTitle:(NSString *)titleText action:(void (^)(JTAlertView *alertView))action { - [self addButtonWithTitle:titleText style:JTAlertViewStyleDefault action:action]; } - (void)addButtonWithTitle:(NSString *)titleText style:(JTAlertViewStyle)style action:(void (^)(JTAlertView *alertView))action { - [self addButtonWithTitle:titleText style:style forControlEvents:UIControlEventTouchUpInside action:action]; } @@ -90,45 +88,57 @@ - (void)addButtonWithTitle:(NSString *)titleText style:(JTAlertViewStyle)style f } - (void)addButtonWithTitle:(NSString *)titleText font:(UIFont *)font style:(JTAlertViewStyle)style forControlEvents:(UIControlEvents)controlEvents action:(void (^)(JTAlertView *alertView))action { + JTAlertViewStyling styling = ^(UIButton *btn) { + [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; + [btn setBackgroundColor:[UIColor whiteColor]]; + if (!font) { + switch (style) { + case JTAlertViewStyleDefault: + btn.titleLabel.font = [_font fontWithSize:kBtnFontSize]; + break; + case JTAlertViewStyleCancel: + btn.titleLabel.font = [self boldForFont:_font withSize:kBtnFontSize] ? [self boldForFont:_font withSize:kBtnFontSize] : [_font fontWithSize:kBtnFontSize]; + break; + case JTAlertViewStyleDestructive: + btn.titleLabel.font = [self boldForFont:_font withSize:kBtnFontSize] ? [self boldForFont:_font withSize:kBtnFontSize] : [_font fontWithSize:kBtnFontSize]; + + [btn setTitleColor:[UIColor colorWithRed:0.906 green:0.298 blue:0.235 alpha:1] forState:UIControlStateNormal]; + break; + default: + break; + } + } else { + switch (style) { + case JTAlertViewStyleDefault: + btn.titleLabel.font = font; + break; + case JTAlertViewStyleCancel: + btn.titleLabel.font = [self boldForFont:font withSize:font.pointSize] ? [self boldForFont:font withSize:font.pointSize] : font; + break; + case JTAlertViewStyleDestructive: + btn.titleLabel.font = [self boldForFont:font withSize:font.pointSize] ? [self boldForFont:font withSize:font.pointSize] : font; + + [btn setTitleColor:[UIColor colorWithRed:0.906 green:0.298 blue:0.235 alpha:1] forState:UIControlStateNormal]; + break; + default: + break; + } + } + }; + [self addButtonWithTitle:titleText styling:styling forControlEvents:controlEvents action:action]; +} + +- (void)addButtonWithTitle:(NSString *)titleText styling:(JTAlertViewStyling)styling forControlEvents:(UIControlEvents)controlEvents action:(void (^)(JTAlertView *alertView))action { UIBlockButton *btn = [UIBlockButton buttonWithType:UIButtonTypeSystem]; - [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; - [btn setBackgroundColor:[UIColor whiteColor]]; - [btn setTitle:titleText forState:UIControlStateNormal]; - [btn handleControlEvent:controlEvents withBlock:action]; - if (!font) { - switch (style) { - case JTAlertViewStyleDefault: - btn.titleLabel.font = [_font fontWithSize:kBtnFontSize]; - break; - case JTAlertViewStyleCancel: - btn.titleLabel.font = [self boldForFont:_font withSize:kBtnFontSize] ? [self boldForFont:_font withSize:kBtnFontSize] : [_font fontWithSize:kBtnFontSize]; - break; - case JTAlertViewStyleDestructive: - btn.titleLabel.font = [self boldForFont:_font withSize:kBtnFontSize] ? [self boldForFont:_font withSize:kBtnFontSize] : [_font fontWithSize:kBtnFontSize]; - [btn setTitleColor:[UIColor colorWithRed:0.906 green:0.298 blue:0.235 alpha:1] forState:UIControlStateNormal]; - break; - default: - break; - } - } else { - switch (style) { - case JTAlertViewStyleDefault: - btn.titleLabel.font = font; - break; - case JTAlertViewStyleCancel: - btn.titleLabel.font = [self boldForFont:font withSize:font.pointSize] ? [self boldForFont:font withSize:font.pointSize] : font; - break; - case JTAlertViewStyleDestructive: - btn.titleLabel.font = [self boldForFont:font withSize:font.pointSize] ? [self boldForFont:font withSize:font.pointSize] : font; - [btn setTitleColor:[UIColor colorWithRed:0.906 green:0.298 blue:0.235 alpha:1] forState:UIControlStateNormal]; - break; - default: - break; - } + if (styling != nil) { + styling(btn); } + [btn setTitle:titleText forState:UIControlStateNormal]; + [btn handleControlEvent:controlEvents withBlock:action]; + [self.btns addObject:btn]; [self layoutBtns]; @@ -165,7 +175,7 @@ - (void)layoutBtns { - (void)addSeparatorInView:(UIView *)superview withTag:(NSInteger)tag andFrame:(CGRect)frame { UIView *separator = [[UIView alloc] initWithFrame:frame]; - separator.backgroundColor = [UIColor colorWithWhite:kSeparatorColorValue alpha:1.0]; + separator.backgroundColor = self.separatorColor; separator.tag = tag; [superview insertSubview:separator atIndex:2]; } @@ -243,7 +253,6 @@ - (void)show { } - (void)showInSuperview:(UIView *)superView withCompletion:(void (^)())completion animated:(bool)animated { - if (self.btns.count == 0) { [self applyAppearanceConsideringButtons:false]; } else { @@ -359,6 +368,7 @@ - (void)defaultSetup { _titleColor = [UIColor whiteColor]; _titleShadow = true; _backgroundShadow = false; + _separatorColor = [UIColor colorWithWhite:kSeparatorColorValue alpha:1.0]; } - (void)noAlpha { @@ -433,4 +443,4 @@ - (void)callActionBlock { _actionBlock((JTAlertView *)self.superview); } -@end \ No newline at end of file +@end