Created
January 27, 2012 13:00
-
-
Save dhoerl/1688664 to your computer and use it in GitHub Desktop.
UIActionSheet Subclass providing ability to set Font and Alignment for the message. Please advice if your app with it gets accepted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LTActionSheet - a UIActionSheet subclass to support customized fonts and alignment | |
Copyright (C) 2011 by David Hoerl | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
@interface LTActionSheet : UIActionSheet | |
@property (nonatomic, assign) UITextAlignment alignment; | |
@property (nonatomic, strong) UIFont *font; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LTActionSheet - a UIActionSheet subclass to support customized fonts and alignment | |
Copyright (C) 2011 by David Hoerl | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
*/ | |
#import "LTActionSheet.h" | |
#if ! __has_feature(objc_arc) | |
#error THIS CODE MUST BE COMPILED WITH ARC ENABLED! | |
#endif | |
@implementation LTActionSheet | |
{ | |
BOOL didShow; | |
} | |
@synthesize alignment; | |
@synthesize font; | |
- (void)showInView:(UIView *)view | |
{ | |
[super showInView:view]; | |
if(didShow) return; | |
didShow = YES; | |
CGFloat diff; | |
for(UILabel *label in [super subviews]) { | |
if([label isKindOfClass:[UILabel class]]) { | |
//NSLog(@"Orig Label=%@ MASK=0x%x", NSStringFromCGRect(label.frame), label.autoresizingMask ); | |
CGRect frame = label.frame; | |
label.autoresizingMask = UIViewAutoresizingFlexibleHeight; | |
label.textAlignment = UITextAlignmentLeft; | |
label.font = font; | |
label.numberOfLines = 100; | |
label.lineBreakMode = UILineBreakModeWordWrap; | |
diff = frame.size.height; | |
frame.size.height = 10000; | |
CGRect r = [label textRectForBounds:frame limitedToNumberOfLines:1000]; | |
diff = rintf(r.size.height - diff); | |
label.frame = r; | |
//NSLog(@"OrigBounds=%@ computedBounds=%@", NSStringFromCGRect(frame), NSStringFromCGRect(r) ); | |
//NSLog(@"Label=%@", NSStringFromCGRect(label.frame) ); | |
break; | |
} | |
} | |
CGRect frame = super.frame; | |
frame.size.height += diff; | |
frame.origin.y -= diff; | |
super.frame = frame; | |
for(UIView *sview in [super subviews]) { | |
frame = sview.frame; | |
if([sview isKindOfClass:[UILabel class]]) frame.origin.y -= rintf(diff/2); | |
else frame.origin.y += diff; | |
sview.frame = frame; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Customizable Action Sheet for iOS. Uses ARC so may need small changes for pre-ARC compilation. Create the action sheet, then set the font and alignment, then show it as you would an action sheet.