Skip to content

Commit a1c326c

Browse files
trispokyoji2
authored andcommitted
Add support for changing the button images
1 parent 0b2601e commit a1c326c

16 files changed

Lines changed: 124 additions & 24 deletions

SIAlertView/SIAlertView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
6262
@property (nonatomic, assign) CGFloat cornerRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 2.0
6363
@property (nonatomic, assign) CGFloat shadowRadius NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR; // default is 8.0
6464

65+
- (void)setDefaultButtonImage:(UIImage *)defaultButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
66+
- (void)setCancelButtonImage:(UIImage *)cancelButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
67+
- (void)setDestructiveButtonImage:(UIImage *)destructiveButtonImage forState:(UIControlState)state NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
68+
6569
- (id)initWithTitle:(NSString *)title andMessage:(NSString *)message;
6670
- (void)addButtonWithTitle:(NSString *)title type:(SIAlertViewButtonType)type handler:(SIAlertViewHandler)handler;
6771

SIAlertView/SIAlertView.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,39 @@ - (void)setDestructiveButtonColor:(UIColor *)buttonColor
10241024
[self setColor:buttonColor toButtonsOfType:SIAlertViewButtonTypeDestructive];
10251025
}
10261026

1027+
1028+
- (void)setDefaultButtonImage:(UIImage *)defaultButtonImage forState:(UIControlState)state
1029+
{
1030+
[self setButtonImage:defaultButtonImage forState:state andButtonType:SIAlertViewButtonTypeDefault];
1031+
}
1032+
1033+
1034+
- (void)setCancelButtonImage:(UIImage *)cancelButtonImage forState:(UIControlState)state
1035+
{
1036+
[self setButtonImage:cancelButtonImage forState:state andButtonType:SIAlertViewButtonTypeCancel];
1037+
}
1038+
1039+
1040+
- (void)setDestructiveButtonImage:(UIImage *)destructiveButtonImage forState:(UIControlState)state
1041+
{
1042+
[self setButtonImage:destructiveButtonImage forState:state andButtonType:SIAlertViewButtonTypeDestructive];
1043+
}
1044+
1045+
1046+
- (void)setButtonImage:(UIImage *)image forState:(UIControlState)state andButtonType:(SIAlertViewButtonType)type
1047+
{
1048+
for (NSUInteger i = 0; i < self.items.count; i++)
1049+
{
1050+
SIAlertItem *item = self.items[i];
1051+
if(item.type == type)
1052+
{
1053+
UIButton *button = self.buttons[i];
1054+
[button setBackgroundImage:image forState:state];
1055+
}
1056+
}
1057+
}
1058+
1059+
10271060
-(void)setColor:(UIColor *)color toButtonsOfType:(SIAlertViewButtonType)type {
10281061
for (NSUInteger i = 0; i < self.items.count; i++) {
10291062
SIAlertItem *item = self.items[i];

SIAlertViewExample/SIAlertViewExample.xcodeproj/project.pbxproj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
72AD5C9217BD1B7200A85539 /* button-cancel-d.png in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8617BD1B7200A85539 /* button-cancel-d.png */; };
11+
72AD5C9317BD1B7200A85539 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8717BD1B7200A85539 /* [email protected] */; };
12+
72AD5C9417BD1B7200A85539 /* button-cancel.png in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8817BD1B7200A85539 /* button-cancel.png */; };
13+
72AD5C9517BD1B7200A85539 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8917BD1B7200A85539 /* [email protected] */; };
14+
72AD5C9617BD1B7200A85539 /* button-default-d.png in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8A17BD1B7200A85539 /* button-default-d.png */; };
15+
72AD5C9717BD1B7200A85539 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8B17BD1B7200A85539 /* [email protected] */; };
16+
72AD5C9817BD1B7200A85539 /* button-default.png in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8C17BD1B7200A85539 /* button-default.png */; };
17+
72AD5C9917BD1B7200A85539 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8D17BD1B7200A85539 /* [email protected] */; };
18+
72AD5C9A17BD1B7200A85539 /* button-destructive-d.png in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8E17BD1B7200A85539 /* button-destructive-d.png */; };
19+
72AD5C9B17BD1B7200A85539 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C8F17BD1B7200A85539 /* [email protected] */; };
20+
72AD5C9C17BD1B7200A85539 /* button-destructive.png in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C9017BD1B7200A85539 /* button-destructive.png */; };
21+
72AD5C9D17BD1B7200A85539 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 72AD5C9117BD1B7200A85539 /* [email protected] */; };
1022
7E23C67317325EAA00784CF1 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E23C67217325EAA00784CF1 /* UIKit.framework */; };
1123
7E23C67517325EAA00784CF1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E23C67417325EAA00784CF1 /* Foundation.framework */; };
1224
7E23C67717325EAA00784CF1 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E23C67617325EAA00784CF1 /* CoreGraphics.framework */; };
@@ -29,6 +41,18 @@
2941
/* End PBXBuildFile section */
3042

3143
/* Begin PBXFileReference section */
44+
72AD5C8617BD1B7200A85539 /* button-cancel-d.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button-cancel-d.png"; sourceTree = "<group>"; };
45+
72AD5C8717BD1B7200A85539 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
46+
72AD5C8817BD1B7200A85539 /* button-cancel.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button-cancel.png"; sourceTree = "<group>"; };
47+
72AD5C8917BD1B7200A85539 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
48+
72AD5C8A17BD1B7200A85539 /* button-default-d.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button-default-d.png"; sourceTree = "<group>"; };
49+
72AD5C8B17BD1B7200A85539 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
50+
72AD5C8C17BD1B7200A85539 /* button-default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button-default.png"; sourceTree = "<group>"; };
51+
72AD5C8D17BD1B7200A85539 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
52+
72AD5C8E17BD1B7200A85539 /* button-destructive-d.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button-destructive-d.png"; sourceTree = "<group>"; };
53+
72AD5C8F17BD1B7200A85539 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
54+
72AD5C9017BD1B7200A85539 /* button-destructive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button-destructive.png"; sourceTree = "<group>"; };
55+
72AD5C9117BD1B7200A85539 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
3256
7E23C66F17325EAA00784CF1 /* SIAlertViewExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SIAlertViewExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
3357
7E23C67217325EAA00784CF1 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
3458
7E23C67417325EAA00784CF1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -71,6 +95,25 @@
7195
/* End PBXFrameworksBuildPhase section */
7296

7397
/* Begin PBXGroup section */
98+
72AD5C8517BD1B7200A85539 /* Button Images */ = {
99+
isa = PBXGroup;
100+
children = (
101+
72AD5C8617BD1B7200A85539 /* button-cancel-d.png */,
102+
72AD5C8717BD1B7200A85539 /* [email protected] */,
103+
72AD5C8817BD1B7200A85539 /* button-cancel.png */,
104+
72AD5C8917BD1B7200A85539 /* [email protected] */,
105+
72AD5C8A17BD1B7200A85539 /* button-default-d.png */,
106+
72AD5C8B17BD1B7200A85539 /* [email protected] */,
107+
72AD5C8C17BD1B7200A85539 /* button-default.png */,
108+
72AD5C8D17BD1B7200A85539 /* [email protected] */,
109+
72AD5C8E17BD1B7200A85539 /* button-destructive-d.png */,
110+
72AD5C8F17BD1B7200A85539 /* [email protected] */,
111+
72AD5C9017BD1B7200A85539 /* button-destructive.png */,
112+
72AD5C9117BD1B7200A85539 /* [email protected] */,
113+
);
114+
path = "Button Images";
115+
sourceTree = "<group>";
116+
};
74117
7E23C66617325EAA00784CF1 = {
75118
isa = PBXGroup;
76119
children = (
@@ -103,6 +146,7 @@
103146
7E23C67817325EAA00784CF1 /* SIAlertViewExample */ = {
104147
isa = PBXGroup;
105148
children = (
149+
72AD5C8517BD1B7200A85539 /* Button Images */,
106150
7E23C6A41732776700784CF1 /* Icons */,
107151
7E23C6A5173277AB00784CF1 /* UI */,
108152
7E23C6A6173277B600784CF1 /* Classes */,
@@ -230,6 +274,18 @@
230274
7E23C6A31732776100784CF1 /* [email protected] in Resources */,
231275
7E23C6A8173277EA00784CF1 /* Icon-72.png in Resources */,
232276
7E23C6AA173277EE00784CF1 /* [email protected] in Resources */,
277+
72AD5C9217BD1B7200A85539 /* button-cancel-d.png in Resources */,
278+
72AD5C9317BD1B7200A85539 /* [email protected] in Resources */,
279+
72AD5C9417BD1B7200A85539 /* button-cancel.png in Resources */,
280+
72AD5C9517BD1B7200A85539 /* [email protected] in Resources */,
281+
72AD5C9617BD1B7200A85539 /* button-default-d.png in Resources */,
282+
72AD5C9717BD1B7200A85539 /* [email protected] in Resources */,
283+
72AD5C9817BD1B7200A85539 /* button-default.png in Resources */,
284+
72AD5C9917BD1B7200A85539 /* [email protected] in Resources */,
285+
72AD5C9A17BD1B7200A85539 /* button-destructive-d.png in Resources */,
286+
72AD5C9B17BD1B7200A85539 /* [email protected] in Resources */,
287+
72AD5C9C17BD1B7200A85539 /* button-destructive.png in Resources */,
288+
72AD5C9D17BD1B7200A85539 /* [email protected] in Resources */,
233289
);
234290
runOnlyForDeploymentPostprocessing = 0;
235291
};
456 Bytes
Loading
1.63 KB
Loading
462 Bytes
Loading
1.61 KB
Loading
807 Bytes
Loading
2.77 KB
Loading
778 Bytes
Loading

0 commit comments

Comments
 (0)