Skip to content

Commit aee526a

Browse files
0xcedAlanQuatermain
authored andcommitted
Embed all AQGridSelection* pngs
1 parent 52e6cfb commit aee526a

3 files changed

Lines changed: 48 additions & 7 deletions

File tree

AQGridView.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
isa = PBXNativeTarget;
194194
buildConfigurationList = 1DEB921E08733DC00010E9CD /* Build configuration list for PBXNativeTarget "AQGridView" */;
195195
buildPhases = (
196+
DA62444512102F6E007EC097 /* Embed PNGs */,
196197
D2AAC07A0554694100DB518D /* Headers */,
197198
D2AAC07B0554694100DB518D /* Sources */,
198199
D2AAC07C0554694100DB518D /* Frameworks */,
@@ -224,6 +225,29 @@
224225
};
225226
/* End PBXProject section */
226227

228+
/* Begin PBXShellScriptBuildPhase section */
229+
DA62444512102F6E007EC097 /* Embed PNGs */ = {
230+
isa = PBXShellScriptBuildPhase;
231+
buildActionMask = 12;
232+
files = (
233+
);
234+
inputPaths = (
235+
"$(SRCROOT)/Resources/AQGridSelection.png",
236+
"$(SRCROOT)/Resources/AQGridSelectionGray.png",
237+
"$(SRCROOT)/Resources/AQGridSelectionGrayBlue.png",
238+
"$(SRCROOT)/Resources/AQGridSelectionGreen.png",
239+
"$(SRCROOT)/Resources/AQGridSelectionRed.png",
240+
);
241+
name = "Embed PNGs";
242+
outputPaths = (
243+
"$(DERIVED_FILES_DIR)/AQGridViewCell_png.h",
244+
);
245+
runOnlyForDeploymentPostprocessing = 0;
246+
shellPath = /bin/bash;
247+
shellScript = ". \"${SRCROOT}/Scripts/embed_png.sh\"\n";
248+
};
249+
/* End PBXShellScriptBuildPhase section */
250+
227251
/* Begin PBXSourcesBuildPhase section */
228252
D2AAC07B0554694100DB518D /* Sources */ = {
229253
isa = PBXSourcesBuildPhase;

Classes/AQGridViewCell.m

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#import "AQGridViewCell+AQGridViewCellPrivate.h"
3939
#import "UIColor+AQGridView.h"
4040
#import <QuartzCore/QuartzCore.h>
41-
#import <objc/runtime.h>
41+
#import "AQGridViewCell_png.h"
4242

4343
@interface AQGridViewCell ()
4444
@property (nonatomic, retain) UIView * contentView;
@@ -297,31 +297,37 @@ - (void) _beginBackgroundHighlight: (BOOL) highlightOn animated: (BOOL) animated
297297
{
298298
if ( (_cellFlags.usingDefaultSelectedBackgroundView == 1) && (_selectedBackgroundView == nil) )
299299
{
300-
NSString * imageName = @"AQGridSelection.png";
300+
unsigned char * pngBytes = AQGridSelection_png;
301+
NSUInteger pngLength = AQGridSelection_png_len;
301302
switch ( _cellFlags.selectionStyle )
302303
{
303304
case AQGridViewCellSelectionStyleBlue:
304305
default:
305306
break;
306307

307308
case AQGridViewCellSelectionStyleGray:
308-
imageName = @"AQGridSelectionGray.png";
309+
pngBytes = AQGridSelectionGray_png;
310+
pngLength = AQGridSelectionGray_png_len;
309311
break;
310312

311313
case AQGridViewCellSelectionStyleBlueGray:
312-
imageName = @"AQGridSelectionGrayBlue.png";
314+
pngBytes = AQGridSelectionGrayBlue_png;
315+
pngLength = AQGridSelectionGrayBlue_png_len;
313316
break;
314317

315318
case AQGridViewCellSelectionStyleGreen:
316-
imageName = @"AQGridSelectionGreen.png";
319+
pngBytes = AQGridSelectionGreen_png;
320+
pngLength = AQGridSelectionGreen_png_len;
317321
break;
318322

319323
case AQGridViewCellSelectionStyleRed:
320-
imageName = @"AQGridSelectionRed.png";
324+
pngBytes = AQGridSelectionRed_png;
325+
pngLength = AQGridSelectionRed_png_len;
321326
break;
322327
}
323328

324-
_selectedBackgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: imageName]];
329+
NSData *pngData = [NSData dataWithBytesNoCopy: pngBytes length: pngLength freeWhenDone: NO];
330+
_selectedBackgroundView = [[UIImageView alloc] initWithImage: [UIImage imageWithData: pngData]];
325331
_selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
326332
_selectedBackgroundView.contentMode = UIViewContentModeScaleToFill;
327333
}

Scripts/embed_png.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
PNG_HEADER="${DERIVED_FILES_DIR}/AQGridViewCell_png.h"
4+
5+
rm -f "${PNG_HEADER}"
6+
mkdir -p "${DERIVED_FILES_DIR}"
7+
8+
cd Resources
9+
for png in *; do
10+
xxd -i "$png" >> "${PNG_HEADER}"
11+
done

0 commit comments

Comments
 (0)