From aee526a5b6cf12525057df44d512e15f5e2a65d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Luthi?= Date: Mon, 9 Aug 2010 21:26:15 +0800 Subject: [PATCH] Embed all AQGridSelection* pngs --- AQGridView.xcodeproj/project.pbxproj | 24 ++++++++++++++++++++++++ Classes/AQGridViewCell.m | 20 +++++++++++++------- Scripts/embed_png.sh | 11 +++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100755 Scripts/embed_png.sh diff --git a/AQGridView.xcodeproj/project.pbxproj b/AQGridView.xcodeproj/project.pbxproj index abf0644..d56640d 100644 --- a/AQGridView.xcodeproj/project.pbxproj +++ b/AQGridView.xcodeproj/project.pbxproj @@ -193,6 +193,7 @@ isa = PBXNativeTarget; buildConfigurationList = 1DEB921E08733DC00010E9CD /* Build configuration list for PBXNativeTarget "AQGridView" */; buildPhases = ( + DA62444512102F6E007EC097 /* Embed PNGs */, D2AAC07A0554694100DB518D /* Headers */, D2AAC07B0554694100DB518D /* Sources */, D2AAC07C0554694100DB518D /* Frameworks */, @@ -224,6 +225,29 @@ }; /* End PBXProject section */ +/* Begin PBXShellScriptBuildPhase section */ + DA62444512102F6E007EC097 /* Embed PNGs */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 12; + files = ( + ); + inputPaths = ( + "$(SRCROOT)/Resources/AQGridSelection.png", + "$(SRCROOT)/Resources/AQGridSelectionGray.png", + "$(SRCROOT)/Resources/AQGridSelectionGrayBlue.png", + "$(SRCROOT)/Resources/AQGridSelectionGreen.png", + "$(SRCROOT)/Resources/AQGridSelectionRed.png", + ); + name = "Embed PNGs"; + outputPaths = ( + "$(DERIVED_FILES_DIR)/AQGridViewCell_png.h", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/bash; + shellScript = ". \"${SRCROOT}/Scripts/embed_png.sh\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ D2AAC07B0554694100DB518D /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/Classes/AQGridViewCell.m b/Classes/AQGridViewCell.m index ae554e8..f22cffd 100644 --- a/Classes/AQGridViewCell.m +++ b/Classes/AQGridViewCell.m @@ -38,7 +38,7 @@ #import "AQGridViewCell+AQGridViewCellPrivate.h" #import "UIColor+AQGridView.h" #import -#import +#import "AQGridViewCell_png.h" @interface AQGridViewCell () @property (nonatomic, retain) UIView * contentView; @@ -297,7 +297,8 @@ - (void) _beginBackgroundHighlight: (BOOL) highlightOn animated: (BOOL) animated { if ( (_cellFlags.usingDefaultSelectedBackgroundView == 1) && (_selectedBackgroundView == nil) ) { - NSString * imageName = @"AQGridSelection.png"; + unsigned char * pngBytes = AQGridSelection_png; + NSUInteger pngLength = AQGridSelection_png_len; switch ( _cellFlags.selectionStyle ) { case AQGridViewCellSelectionStyleBlue: @@ -305,23 +306,28 @@ - (void) _beginBackgroundHighlight: (BOOL) highlightOn animated: (BOOL) animated break; case AQGridViewCellSelectionStyleGray: - imageName = @"AQGridSelectionGray.png"; + pngBytes = AQGridSelectionGray_png; + pngLength = AQGridSelectionGray_png_len; break; case AQGridViewCellSelectionStyleBlueGray: - imageName = @"AQGridSelectionGrayBlue.png"; + pngBytes = AQGridSelectionGrayBlue_png; + pngLength = AQGridSelectionGrayBlue_png_len; break; case AQGridViewCellSelectionStyleGreen: - imageName = @"AQGridSelectionGreen.png"; + pngBytes = AQGridSelectionGreen_png; + pngLength = AQGridSelectionGreen_png_len; break; case AQGridViewCellSelectionStyleRed: - imageName = @"AQGridSelectionRed.png"; + pngBytes = AQGridSelectionRed_png; + pngLength = AQGridSelectionRed_png_len; break; } - _selectedBackgroundView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: imageName]]; + NSData *pngData = [NSData dataWithBytesNoCopy: pngBytes length: pngLength freeWhenDone: NO]; + _selectedBackgroundView = [[UIImageView alloc] initWithImage: [UIImage imageWithData: pngData]]; _selectedBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; _selectedBackgroundView.contentMode = UIViewContentModeScaleToFill; } diff --git a/Scripts/embed_png.sh b/Scripts/embed_png.sh new file mode 100755 index 0000000..88dbbe9 --- /dev/null +++ b/Scripts/embed_png.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +PNG_HEADER="${DERIVED_FILES_DIR}/AQGridViewCell_png.h" + +rm -f "${PNG_HEADER}" +mkdir -p "${DERIVED_FILES_DIR}" + +cd Resources +for png in *; do + xxd -i "$png" >> "${PNG_HEADER}" +done