Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Updated for iPhone 5 Compatability #2

Merged
merged 1 commit into from

2 participants

@leolobato
Owner

No description provided.

@Stunner Stunner Updated to be compatible with iPhone 5 4 inch screen. Fine tuned alig…
…ning on picker in both landscape and portrait orientation. Tested with iOS version 4.3, 5.0 and 6.0 on standard 3.5 inch screen, retina 3.5 inch, and 4 in screens in simulator. Updated sample code to be testable on 4 inch screen (added 4 inch splash image).
9c422f8
@leolobato leolobato merged commit 9c422f8 into leolobato:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 6, 2013
  1. @Stunner

    Updated to be compatible with iPhone 5 4 inch screen. Fine tuned alig…

    Stunner authored
    …ning on picker in both landscape and portrait orientation. Tested with iOS version 4.3, 5.0 and 6.0 on standard 3.5 inch screen, retina 3.5 inch, and 4 in screens in simulator. Updated sample code to be testable on 4 inch screen (added 4 inch splash image).
This page is out of date. Refresh to see the latest.
View
64 Pickers/AbstractActionSheetPicker.m
@@ -45,6 +45,7 @@ - (void)configureAndPresentActionSheetForView:(UIView *)aView;
- (void)presentActionSheet:(UIActionSheet *)actionSheet;
- (void)presentPopover:(UIPopoverController *)popover;
- (void)dismissPicker;
++ (BOOL)hasFourInchScreen; // taken from: http://stackoverflow.com/a/12502356/347339
- (BOOL)isViewPortrait;
- (BOOL)isValidOrigin:(id)origin;
- (id)storedOrigin;
@@ -119,7 +120,7 @@ - (UIView *)configuredPickerView {
return nil;
}
-- (void)notifyTarget:(id)target didSucceedWithAction:(SEL)successAction origin:(id)origin {
+- (void)notifyTarget:(id)target didSucceedWithAction:(SEL)successAction origin:(id)origin {
NSAssert(NO, @"This is an abstract class, you must use a subclass of AbstractActionSheetPicker (like ActionSheetStringPicker)");
}
@@ -131,7 +132,7 @@ - (void)notifyTarget:(id)target didCancelWithAction:(SEL)cancelAction origin:(id
#pragma mark - Actions
- (void)showActionSheetPicker {
- UIView *masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.viewSize.width, 260)];
+ UIView *masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.viewSize.width, 260)];
UIToolbar *pickerToolbar = [self createPickerToolbarWithTitle:self.title];
[pickerToolbar setBarStyle:UIBarStyleBlackTranslucent];
[masterView addSubview:pickerToolbar];
@@ -143,7 +144,7 @@ - (void)showActionSheetPicker {
}
- (IBAction)actionPickerDone:(id)sender {
- [self notifyTarget:self.target didSucceedWithAction:self.successAction origin:[self storedOrigin]];
+ [self notifyTarget:self.target didSucceedWithAction:self.successAction origin:[self storedOrigin]];
[self dismissPicker];
}
@@ -156,11 +157,11 @@ - (void)dismissPicker {
#if __IPHONE_4_1 <= __IPHONE_OS_VERSION_MAX_ALLOWED
if (self.actionSheet)
#else
- if (self.actionSheet && [self.actionSheet isVisible])
+ if (self.actionSheet && [self.actionSheet isVisible])
#endif
- [_actionSheet dismissWithClickedButtonIndex:0 animated:YES];
- else if (self.popOverController && self.popOverController.popoverVisible)
- [_popOverController dismissPopoverAnimated:YES];
+ [_actionSheet dismissWithClickedButtonIndex:0 animated:YES];
+ else if (self.popOverController && self.popOverController.popoverVisible)
+ [_popOverController dismissPopoverAnimated:YES];
self.actionSheet = nil;
self.popOverController = nil;
self.selfReference = nil;
@@ -205,7 +206,7 @@ - (UIToolbar *)createPickerToolbarWithTitle:(NSString *)title {
NSInteger index = 0;
for (NSDictionary *buttonDetails in self.customButtons) {
NSString *buttonTitle = [buttonDetails objectForKey:@"buttonTitle"];
- //NSInteger buttonValue = [[buttonDetails objectForKey:@"buttonValue"] intValue];
+ //NSInteger buttonValue = [[buttonDetails objectForKey:@"buttonValue"] intValue];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:buttonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(customButtonPressed:)];
button.tag = index;
[barItems addObject:button];
@@ -220,7 +221,7 @@ - (UIToolbar *)createPickerToolbarWithTitle:(NSString *)title {
[barItems addObject:flexSpace];
if (title){
UIBarButtonItem *labelButton = [self createToolbarLabelWithTitle:title];
- [barItems addObject:labelButton];
+ [barItems addObject:labelButton];
[barItems addObject:flexSpace];
}
UIBarButtonItem *doneButton = [self createButtonWithType:UIBarButtonSystemItemDone target:self action:@selector(actionPickerDone:)];
@@ -232,13 +233,13 @@ - (UIToolbar *)createPickerToolbarWithTitle:(NSString *)title {
- (UIBarButtonItem *)createToolbarLabelWithTitle:(NSString *)aTitle {
UILabel *toolBarItemlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 180,30)];
- [toolBarItemlabel setTextAlignment:UITextAlignmentCenter];
- [toolBarItemlabel setTextColor:[UIColor whiteColor]];
- [toolBarItemlabel setFont:[UIFont boldSystemFontOfSize:16]];
- [toolBarItemlabel setBackgroundColor:[UIColor clearColor]];
- toolBarItemlabel.text = aTitle;
+ [toolBarItemlabel setTextAlignment:UITextAlignmentCenter];
+ [toolBarItemlabel setTextColor:[UIColor whiteColor]];
+ [toolBarItemlabel setFont:[UIFont boldSystemFontOfSize:16]];
+ [toolBarItemlabel setBackgroundColor:[UIColor clearColor]];
+ toolBarItemlabel.text = aTitle;
UIBarButtonItem *buttonLabel = [[[UIBarButtonItem alloc]initWithCustomView:toolBarItemlabel] autorelease];
- [toolBarItemlabel release];
+ [toolBarItemlabel release];
return buttonLabel;
}
@@ -248,10 +249,25 @@ - (UIBarButtonItem *)createButtonWithType:(UIBarButtonSystemItem)type target:(id
#pragma mark - Utilities and Accessors
+// taken from: http://stackoverflow.com/a/12502356/347339
++ (BOOL)hasFourInchScreen {
+ if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+ CGSize result = [[UIScreen mainScreen] bounds].size;
+ if (result.height == 480) {
+ // iPhone Classic
+ } if (result.height == 568) {
+ // iPhone 5
+ return YES;
+ }
+ }
+ return NO;
+}
+
- (CGSize)viewSize {
+ CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (![self isViewPortrait])
- return CGSizeMake(480, 320);
- return CGSizeMake(320, 480);
+ return CGSizeMake(screenSize.height, screenSize.width);
+ return CGSizeMake(screenSize.width, screenSize.height);
}
- (BOOL)isViewPortrait {
@@ -288,14 +304,26 @@ - (void)configureAndPresentActionSheetForView:(UIView *)aView {
CGFloat sheetHeight = self.viewSize.height - 47;
if ([self isViewPortrait]) {
paddedSheetTitle = @"\n\n\n"; // looks hacky to me
+
+ if ([AbstractActionSheetPicker hasFourInchScreen]) {
+ // iPhone 5
+ sheetHeight = self.viewSize.width + 110;
+ }
} else {
NSString *reqSysVer = @"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending) {
- sheetHeight = self.viewSize.width;
+ // 5.0+
+ sheetHeight = self.viewSize.width - 97;
} else {
+ // pre-5.0
sheetHeight += 103;
}
+
+ if ([AbstractActionSheetPicker hasFourInchScreen]) {
+ // iPhone 5
+ sheetHeight = self.viewSize.width - 185;
+ }
}
_actionSheet = [[UIActionSheet alloc] initWithTitle:paddedSheetTitle delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[_actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
View
4 Sample/ActionSheetPicker.xcodeproj/project.pbxproj
@@ -23,6 +23,7 @@
37037557147B73F000B59AA2 /* AbstractActionSheetPicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 37037556147B73EE00B59AA2 /* AbstractActionSheetPicker.m */; };
52CFA62313A4D6FA0022667F /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52CFA62213A4D6FA0022667F /* MainWindow-iPad.xib */; };
52FDE22813A51D2600D8D2C0 /* ActionSheetPickerViewController-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 52FDE22713A51D2600D8D2C0 /* ActionSheetPickerViewController-iPad.xib */; };
+ 93388B0E169982640074F120 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 93388B0D169982640074F120 /* Default-568h@2x.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -54,6 +55,7 @@
52CFA62213A4D6FA0022667F /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
52FDE22713A51D2600D8D2C0 /* ActionSheetPickerViewController-iPad.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "ActionSheetPickerViewController-iPad.xib"; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* ActionSheetPicker-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "ActionSheetPicker-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
+ 93388B0D169982640074F120 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -129,6 +131,7 @@
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
+ 93388B0D169982640074F120 /* Default-568h@2x.png */,
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
@@ -233,6 +236,7 @@
2899E5220DE3E06400AC0155 /* ActionSheetPickerViewController.xib in Resources */,
52CFA62313A4D6FA0022667F /* MainWindow-iPad.xib in Resources */,
52FDE22813A51D2600D8D2C0 /* ActionSheetPickerViewController-iPad.xib in Resources */,
+ 93388B0E169982640074F120 /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN  Sample/Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Something went wrong with that request. Please try again.