Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Alert improvement. #10

Open
wants to merge 8 commits into from

1 participant

@elpablo

Hi, I've made small changes to the original source code:

  • removed the external png images, and now the default background is drawn by the widget itself.
  • fixed the resize mask to be able to resize correctly during the device orientation change. If you like these changes you can merge the pull request :) Cheers. Paolo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 18, 2012
  1. @elpablo
  2. @elpablo

    Draw bg image using code.

    elpablo authored
  3. @elpablo

    Fixed autoresizing mask.

    elpablo authored
  4. @elpablo

    Fixed the draw background gradient and layout backgroundImageView onl…

    elpablo authored
    …y if there is a custom BG image.
  5. @elpablo

    Removed extra files.

    elpablo authored
    Removed not needed anymore files.
  6. @elpablo

    Ignore file

    elpablo authored
  7. @elpablo

    Removed files.

    elpablo authored
  8. @elpablo

    Fixed memory leak.

    elpablo authored
This page is out of date. Refresh to see the latest.
View
8 .gitignore
@@ -0,0 +1,8 @@
+
+.DS_Store
+
+YRDropdownExample.xcodeproj/project.xcworkspace/xcuserdata/quadrani.xcuserdatad/UserInterfaceState.xcuserstate
+
+YRDropdownExample.xcodeproj/xcuserdata/quadrani.xcuserdatad/xcschemes/YRDropdownExample.xcscheme
+
+YRDropdownExample.xcodeproj/xcuserdata/quadrani.xcuserdatad/xcschemes/xcschememanagement.plist
View
28 YRDropdownExample.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 01B3592615165DCA001F266C /* YRDropdownView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01B3592315165DCA001F266C /* YRDropdownView.m */; };
2D3DC25114D73F8E00898E62 /* dropdown-alert@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2D3DC24F14D73F8E00898E62 /* dropdown-alert@2x.png */; };
2D3DC25214D73F8E00898E62 /* dropdown-alert.png in Resources */ = {isa = PBXBuildFile; fileRef = 2D3DC25014D73F8E00898E62 /* dropdown-alert.png */; };
2D5FCB4D14D30C2C00DA334B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D5FCB4C14D30C2C00DA334B /* UIKit.framework */; };
@@ -17,12 +18,11 @@
2D5FCB5D14D30C2C00DA334B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D5FCB5C14D30C2C00DA334B /* AppDelegate.m */; };
2D5FCB6014D30C2C00DA334B /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D5FCB5F14D30C2C00DA334B /* ViewController.m */; };
2D5FCB6314D30C2C00DA334B /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2D5FCB6114D30C2C00DA334B /* ViewController.xib */; };
- 2DC084D814D878460013863F /* bg-yellow.png in Resources */ = {isa = PBXBuildFile; fileRef = 2DC084D414D878460013863F /* bg-yellow.png */; };
- 2DC084D914D878460013863F /* bg-yellow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2DC084D514D878460013863F /* bg-yellow@2x.png */; };
- 2DC084DA14D878460013863F /* YRDropdownView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DC084D714D878460013863F /* YRDropdownView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ 01B3592215165DCA001F266C /* YRDropdownView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YRDropdownView.h; sourceTree = "<group>"; };
+ 01B3592315165DCA001F266C /* YRDropdownView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YRDropdownView.m; sourceTree = "<group>"; };
2D3DC24F14D73F8E00898E62 /* dropdown-alert@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropdown-alert@2x.png"; sourceTree = "<group>"; };
2D3DC25014D73F8E00898E62 /* dropdown-alert.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropdown-alert.png"; sourceTree = "<group>"; };
2D5FCB4814D30C2B00DA334B /* YRDropdownExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YRDropdownExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -39,10 +39,6 @@
2D5FCB5F14D30C2C00DA334B /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
2D5FCB6214D30C2C00DA334B /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
2D5FCB7214D321BC00DA334B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
- 2DC084D414D878460013863F /* bg-yellow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "bg-yellow.png"; path = "YRDropdownView/bg-yellow.png"; sourceTree = "<group>"; };
- 2DC084D514D878460013863F /* bg-yellow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "bg-yellow@2x.png"; path = "YRDropdownView/bg-yellow@2x.png"; sourceTree = "<group>"; };
- 2DC084D614D878460013863F /* YRDropdownView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = YRDropdownView.h; path = YRDropdownView/YRDropdownView.h; sourceTree = "<group>"; };
- 2DC084D714D878460013863F /* YRDropdownView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = YRDropdownView.m; path = YRDropdownView/YRDropdownView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -59,16 +55,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
- 2D3DC25414D7419F00898E62 /* YRDropdownView */ = {
+ 01B3591F15165DCA001F266C /* YRDropdownView */ = {
isa = PBXGroup;
children = (
- 2DC084D414D878460013863F /* bg-yellow.png */,
- 2DC084D514D878460013863F /* bg-yellow@2x.png */,
- 2DC084D614D878460013863F /* YRDropdownView.h */,
- 2DC084D714D878460013863F /* YRDropdownView.m */,
+ 01B3592215165DCA001F266C /* YRDropdownView.h */,
+ 01B3592315165DCA001F266C /* YRDropdownView.m */,
);
- name = YRDropdownView;
- sourceTree = "<group>";
+ path = YRDropdownView;
+ sourceTree = SOURCE_ROOT;
};
2D5FCB3D14D30C2B00DA334B = {
isa = PBXGroup;
@@ -104,8 +98,8 @@
2D5FCB5B14D30C2C00DA334B /* AppDelegate.h */,
2D5FCB5C14D30C2C00DA334B /* AppDelegate.m */,
2DC084D314D878180013863F /* View Controller */,
+ 01B3591F15165DCA001F266C /* YRDropdownView */,
2D5FCB5314D30C2C00DA334B /* Supporting Files */,
- 2D3DC25414D7419F00898E62 /* YRDropdownView */,
2D3DC24F14D73F8E00898E62 /* dropdown-alert@2x.png */,
2D3DC25014D73F8E00898E62 /* dropdown-alert.png */,
);
@@ -188,8 +182,6 @@
2D5FCB6314D30C2C00DA334B /* ViewController.xib in Resources */,
2D3DC25114D73F8E00898E62 /* dropdown-alert@2x.png in Resources */,
2D3DC25214D73F8E00898E62 /* dropdown-alert.png in Resources */,
- 2DC084D814D878460013863F /* bg-yellow.png in Resources */,
- 2DC084D914D878460013863F /* bg-yellow@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -203,7 +195,7 @@
2D5FCB5914D30C2C00DA334B /* main.m in Sources */,
2D5FCB5D14D30C2C00DA334B /* AppDelegate.m in Sources */,
2D5FCB6014D30C2C00DA334B /* ViewController.m in Sources */,
- 2DC084DA14D878460013863F /* YRDropdownView.m in Sources */,
+ 01B3592615165DCA001F266C /* YRDropdownView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
69 YRDropdownExample/YRDropdownView/YRDropdownView.h
@@ -1,69 +0,0 @@
-//
-// YRDropdownView.h
-// YRDropdownViewExample
-//
-// Created by Eli Perkins on 1/27/12.
-// Copyright (c) 2012 One Mighty Roar. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-#import <QuartzCore/QuartzCore.h>
-
-@interface YRDropdownView : UIView
-{
- NSString *titleText;
- NSString *detailText;
- UILabel *titleLabel;
- UILabel *detailLabel;
- UIImage *backgroundImage;
- UIImageView *backgroundImageView;
- UIImage *accessoryImage;
- UIImageView *accessoryImageView;
- SEL onTouch;
- NSDate *showStarted;
- BOOL shouldAnimate;
-}
-
-@property (copy) NSString *titleText;
-@property (copy) NSString *detailText;
-@property (assign) UIImage *accessoryImage;
-@property (assign) float minHeight;
-@property (nonatomic, assign) UIImage *backgroundImage;
-@property (nonatomic, assign) SEL onTouch;
-@property (assign) BOOL shouldAnimate;
-
-#pragma mark - View methods
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view
- title:(NSString *)title;
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view
- title:(NSString *)title
- detail:(NSString *)detail;
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view
- title:(NSString *)title
- detail:(NSString *)detail
- animated:(BOOL)animated;
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view
- title:(NSString *)title
- detail:(NSString *)detail
- image:(UIImage *)image
- animated:(BOOL)animated;
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view
- title:(NSString *)title
- detail:(NSString *)detail
- image:(UIImage *)image
- animated:(BOOL)animated
- hideAfter:(float)delay;
-
-+ (BOOL)hideDropdownInView:(UIView *)view;
-+ (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated;
-
-#pragma mark -
-- (void)show:(BOOL)animated;
-- (void)hide:(BOOL)animated;
-
-@end
View
406 YRDropdownExample/YRDropdownView/YRDropdownView.m
@@ -1,406 +0,0 @@
-//
-// YRDropdownView.m
-// YRDropdownViewExample
-//
-// Created by Eli Perkins on 1/27/12.
-// Copyright (c) 2012 One Mighty Roar. All rights reserved.
-//
-
-#import "YRDropdownView.h"
-#import <QuartzCore/QuartzCore.h>
-
-@interface UILabel (YRDropdownView)
-- (void)sizeToFitFixedWidth:(CGFloat)fixedWidth;
-@end
-
-@implementation UILabel (YRDropdownView)
-
-
-- (void)sizeToFitFixedWidth:(CGFloat)fixedWidth
-{
- self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, fixedWidth, 0);
- self.lineBreakMode = UILineBreakModeWordWrap;
- self.numberOfLines = 0;
- [self sizeToFit];
-}
-@end
-
-@interface YRDropdownView ()
-- (void)updateTitleLabel:(NSString *)newText;
-- (void)updateDetailLabel:(NSString *)newText;
-- (void)hideUsingAnimation:(NSNumber *)animated;
-- (void)done;
-@end
-
-
-@implementation YRDropdownView
-@synthesize titleText;
-@synthesize detailText;
-@synthesize minHeight;
-@synthesize backgroundImage;
-@synthesize accessoryImage;
-@synthesize onTouch;
-@synthesize shouldAnimate;
-
-//Using this prevents two alerts to ever appear on the screen at the same time
-//TODO: Queue alerts, if multiple
-static YRDropdownView *currentDropdown = nil;
-
-+ (YRDropdownView *)currentDropdownView
-{
- return currentDropdown;
-}
-
-#pragma mark - Accessors
-
-- (NSString *)titleText
-{
- return titleText;
-}
-
-- (void)setTitleText:(NSString *)newText
-{
- if ([NSThread isMainThread]) {
- [self updateTitleLabel:newText];
- [self setNeedsLayout];
- [self setNeedsDisplay];
- } else {
- [self performSelectorOnMainThread:@selector(updateTitleLabel:) withObject:newText waitUntilDone:NO];
- [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
- [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
- }
-}
-
-- (NSString *)detailText
-{
- return detailText;
-}
-
-- (void)setDetailText:(NSString *)newText
-{
- if ([NSThread isMainThread]) {
- [self updateDetailLabel:newText];
- [self setNeedsLayout];
- [self setNeedsDisplay];
- } else {
- [self performSelectorOnMainThread:@selector(updateDetailLabel:) withObject:newText waitUntilDone:NO];
- [self performSelectorOnMainThread:@selector(setNeedsLayout) withObject:nil waitUntilDone:NO];
- [self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:NO];
- }
-}
-
-- (void)updateTitleLabel:(NSString *)newText {
- if (titleText != newText) {
- #if !__has_feature(objc_arc)
- [titleText release];
- #endif
- titleText = [newText copy];
- titleLabel.text = titleText;
- }
-}
-
-- (void)updateDetailLabel:(NSString *)newText {
- if (detailText != newText) {
- #if !__has_feature(objc_arc)
- [detailText release];
- #endif
- detailText = [newText copy];
- detailLabel.text = detailText;
- }
-}
-
-
-
-#pragma mark - Initializers
-- (id)init {
- return [self initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
-}
-
-- (id)initWithFrame:(CGRect)frame
-{
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- self.titleText = nil;
- self.detailText = nil;
- self.minHeight = 44.0f;
- self.backgroundImage = [UIImage imageNamed:@"bg-yellow.png"];
- self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
-
- titleLabel = [[UILabel alloc] initWithFrame:self.bounds];
- detailLabel = [[UILabel alloc] initWithFrame:self.bounds];
- backgroundImageView = [[UIImageView alloc] initWithFrame:self.bounds];
- backgroundImageView.image = [self.backgroundImage stretchableImageWithLeftCapWidth:1 topCapHeight:self.backgroundImage.size.height/2];
- backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
-
- accessoryImageView = [[UIImageView alloc] initWithFrame:self.bounds];
- [self addSubview:backgroundImageView];
-
- self.opaque = YES;
-
- onTouch = @selector(hide:);
- }
- return self;
-}
-
-#pragma mark - Defines
-
-#define HORIZONTAL_PADDING 15.0f
-#define VERTICAL_PADDING 19.0f
-#define IMAGE_PADDING 45.0f
-#define TITLE_FONT_SIZE 19.0f
-#define DETAIL_FONT_SIZE 13.0f
-#define ANIMATION_DURATION 0.3f
-
-#pragma mark - Class methods
-#pragma mark View Methods
-+ (YRDropdownView *)showDropdownInView:(UIView *)view title:(NSString *)title
-{
- return [YRDropdownView showDropdownInView:view title:title detail:nil];
-}
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view title:(NSString *)title detail:(NSString *)detail
-{
- return [YRDropdownView showDropdownInView:view title:title detail:detail image:nil animated:YES];
-}
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view title:(NSString *)title detail:(NSString *)detail animated:(BOOL)animated
-{
- return [YRDropdownView showDropdownInView:view title:title detail:detail image:nil animated:animated hideAfter:0.0];
-}
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view title:(NSString *)title detail:(NSString *)detail image:(UIImage *)image animated:(BOOL)animated
-{
- return [YRDropdownView showDropdownInView:view title:title detail:detail image:image animated:animated hideAfter:0.0];
-}
-
-+ (YRDropdownView *)showDropdownInView:(UIView *)view
- title:(NSString *)title
- detail:(NSString *)detail
- image:(UIImage *)image
- animated:(BOOL)animated
- hideAfter:(float)delay
-{
- if (currentDropdown) {
- [currentDropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
- }
-
- YRDropdownView *dropdown = [[YRDropdownView alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width, 44)];
- currentDropdown = dropdown;
- dropdown.titleText = title;
-
- if (detail) {
- dropdown.detailText = detail;
- }
-
- if (image) {
- dropdown.accessoryImage = image;
- }
-
- dropdown.shouldAnimate = animated;
-
- if ([view isKindOfClass:[UIWindow class]]) {
- CGRect dropdownFrame = dropdown.frame;
- CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
- dropdownFrame.origin.y = appFrame.origin.y;
- dropdown.frame = dropdownFrame;
- }
-
- [view addSubview:dropdown];
- [dropdown show:animated];
- if (delay != 0.0) {
- [dropdown performSelector:@selector(hideUsingAnimation:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay+ANIMATION_DURATION];
- }
-
- return dropdown;
-}
-
-+ (void)removeView
-{
- if (!currentDropdown) {
- return;
- }
-
- [currentDropdown removeFromSuperview];
-
- [currentDropdown release];
- currentDropdown = nil;
-}
-
-+ (BOOL)hideDropdownInView:(UIView *)view
-{
- return [YRDropdownView hideDropdownInView:view animated:YES];
-}
-
-+ (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated
-{
- if (currentDropdown) {
- [currentDropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
- return YES;
- }
-
- UIView *viewToRemove = nil;
- for (UIView *v in [view subviews]) {
- if ([v isKindOfClass:[YRDropdownView class]]) {
- viewToRemove = v;
- }
- }
- if (viewToRemove != nil) {
- YRDropdownView *dropdown = (YRDropdownView *)viewToRemove;
- [dropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
- return YES;
- }
- else {
- return NO;
- }
-}
-
-#pragma mark - Methods
-
-- (void)show:(BOOL)animated
-{
- if(animated)
- {
- self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y-self.frame.size.height, self.frame.size.width, self.frame.size.height);
- self.alpha = 0.02;
- [UIView animateWithDuration:ANIMATION_DURATION
- delay:0.0
- options:UIViewAnimationOptionCurveEaseInOut
- animations:^{
- self.alpha = 1.0;
- self.frame = CGRectMake(self.frame.origin.x,
- self.frame.origin.y+self.frame.size.height,
- self.frame.size.width, self.frame.size.height);
- }
- completion:^(BOOL finished) {
- if (finished)
- {
-
- }
- }];
-
- }
-}
-
-- (void)hide:(BOOL)animated
-{
- [self done];
-}
-
-- (void)hideUsingAnimation:(NSNumber *)animated {
- if ([animated boolValue]) {
- [UIView animateWithDuration:ANIMATION_DURATION
- delay:0.0
- options:UIViewAnimationOptionCurveEaseInOut
- animations:^{
- self.alpha = 0.02;
- self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y-self.frame.size.height, self.frame.size.width, self.frame.size.height);
- }
- completion:^(BOOL finished) {
- if (finished)
- {
- [self done];
- }
- }];
- }
- else {
- self.alpha = 0.0f;
- [self done];
- }
-}
-
-- (void)done
-{
- [self removeFromSuperview];
-}
-
-- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-{
- [self hideUsingAnimation:[NSNumber numberWithBool:self.shouldAnimate]];
-}
-
-#pragma mark - Layout
-
-- (void)layoutSubviews {
- // Set label properties
- titleLabel.font = [UIFont boldSystemFontOfSize:TITLE_FONT_SIZE];
- titleLabel.adjustsFontSizeToFitWidth = NO;
- titleLabel.opaque = NO;
- titleLabel.backgroundColor = [UIColor clearColor];
- titleLabel.textColor = [UIColor colorWithWhite:0.225 alpha:1.0];
- titleLabel.shadowOffset = CGSizeMake(0, 1/[[UIScreen mainScreen] scale]);
- titleLabel.shadowColor = [UIColor colorWithWhite:1 alpha:0.25];
- titleLabel.text = self.titleText;
- [titleLabel sizeToFitFixedWidth:self.bounds.size.width - (2 * HORIZONTAL_PADDING)];
-
- titleLabel.frame = CGRectMake(self.bounds.origin.x + HORIZONTAL_PADDING,
- self.bounds.origin.y + VERTICAL_PADDING - 8,
- self.bounds.size.width - (2 * HORIZONTAL_PADDING),
- titleLabel.frame.size.height);
-
- [self addSubview:titleLabel];
-
- if (self.detailText) {
- detailLabel.font = [UIFont systemFontOfSize:DETAIL_FONT_SIZE];
- detailLabel.numberOfLines = 0;
- detailLabel.adjustsFontSizeToFitWidth = NO;
- detailLabel.opaque = NO;
- detailLabel.backgroundColor = [UIColor clearColor];
- detailLabel.textColor = [UIColor colorWithWhite:0.225 alpha:1.0];
- detailLabel.shadowOffset = CGSizeMake(0, 1/[[UIScreen mainScreen] scale]);
- detailLabel.shadowColor = [UIColor colorWithWhite:1 alpha:0.25];
- detailLabel.text = self.detailText;
- [detailLabel sizeToFitFixedWidth:self.bounds.size.width - (2 * HORIZONTAL_PADDING)];
-
- detailLabel.frame = CGRectMake(self.bounds.origin.x + HORIZONTAL_PADDING,
- titleLabel.frame.origin.y + titleLabel.frame.size.height + 2,
- self.bounds.size.width - (2 * HORIZONTAL_PADDING),
- detailLabel.frame.size.height);
-
- [self addSubview:detailLabel];
- } else {
- titleLabel.frame = CGRectMake(titleLabel.frame.origin.x,
- 9,
- titleLabel.frame.size.width,
- titleLabel.frame.size.height);
- }
-
- if (self.accessoryImage) {
- accessoryImageView.image = self.accessoryImage;
- accessoryImageView.frame = CGRectMake(self.bounds.origin.x + HORIZONTAL_PADDING,
- self.bounds.origin.y + VERTICAL_PADDING,
- self.accessoryImage.size.width,
- self.accessoryImage.size.height);
-
- [titleLabel sizeToFitFixedWidth:self.bounds.size.width - IMAGE_PADDING - (HORIZONTAL_PADDING * 2)];
- titleLabel.frame = CGRectMake(titleLabel.frame.origin.x + IMAGE_PADDING,
- titleLabel.frame.origin.y,
- titleLabel.frame.size.width,
- titleLabel.frame.size.height);
-
- if (self.detailText) {
- [detailLabel sizeToFitFixedWidth:self.bounds.size.width - IMAGE_PADDING - (HORIZONTAL_PADDING * 2)];
- detailLabel.frame = CGRectMake(detailLabel.frame.origin.x + IMAGE_PADDING,
- detailLabel.frame.origin.y,
- detailLabel.frame.size.width,
- detailLabel.frame.size.height);
- }
-
- [self addSubview:accessoryImageView];
- }
-
- CGFloat dropdownHeight = 44.0f;
- if (self.detailText) {
- dropdownHeight = MAX(CGRectGetMaxY(self.bounds), CGRectGetMaxY(detailLabel.frame));
- dropdownHeight += VERTICAL_PADDING;
- }
-
- [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, dropdownHeight)];
-
- [backgroundImageView setFrame:self.bounds];
-
-}
-
-@end
-
-
View
BIN  YRDropdownExample/YRDropdownView/bg-yellow.png
Deleted file not rendered
View
BIN  YRDropdownExample/YRDropdownView/bg-yellow@2x.png
Deleted file not rendered
View
26 YRDropdownExample/en.lproj/ViewController.xib
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
- <int key="IBDocument.SystemTarget">1280</int>
- <string key="IBDocument.SystemVersion">11C74</string>
- <string key="IBDocument.InterfaceBuilderVersion">2166</string>
- <string key="IBDocument.AppKitVersion">1138.23</string>
- <string key="IBDocument.HIToolboxVersion">567.00</string>
+ <int key="IBDocument.SystemTarget">1296</int>
+ <string key="IBDocument.SystemVersion">11D50b</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2182</string>
+ <string key="IBDocument.AppKitVersion">1138.32</string>
+ <string key="IBDocument.HIToolboxVersion">568.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="NS.object.0">1166</string>
+ <string key="NS.object.0">1179</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBProxyObject</string>
@@ -37,7 +37,7 @@
<array class="NSMutableArray" key="NSSubviews">
<object class="IBUIButton" id="13751450">
<reference key="NSNextResponder" ref="774585933"/>
- <int key="NSvFlags">292</int>
+ <int key="NSvFlags">301</int>
<string key="NSFrame">{{124, 300}, {72, 37}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
@@ -73,7 +73,7 @@
</object>
<object class="IBUIView" id="828496946">
<reference key="NSNextResponder" ref="774585933"/>
- <int key="NSvFlags">292</int>
+ <int key="NSvFlags">306</int>
<string key="NSFrame">{{0, 81}, {320, 194}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
@@ -90,7 +90,7 @@
</object>
<object class="IBUIButton" id="258083433">
<reference key="NSNextResponder" ref="774585933"/>
- <int key="NSvFlags">292</int>
+ <int key="NSvFlags">301</int>
<string key="NSFrame">{{119, 352}, {82, 37}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
@@ -113,7 +113,7 @@
</object>
<object class="IBUIButton" id="990659902">
<reference key="NSNextResponder" ref="774585933"/>
- <int key="NSvFlags">292</int>
+ <int key="NSvFlags">269</int>
<string key="NSFrame">{{124, 405}, {72, 37}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
@@ -308,8 +308,12 @@
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
+ <real value="1296" key="NS.object.0"/>
+ </object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
- <string key="IBCocoaTouchPluginVersion">1166</string>
+ <string key="IBCocoaTouchPluginVersion">1179</string>
</data>
</archive>
View
3  YRDropdownView/YRDropdownView.h
@@ -24,6 +24,9 @@
SEL onTouch;
NSDate *showStarted;
BOOL shouldAnimate;
+
+ @private
+ CGGradientRef _backgroundGradient;
}
@property (copy) NSString *titleText;
View
72 YRDropdownView/YRDropdownView.m
@@ -10,7 +10,9 @@
#import <QuartzCore/QuartzCore.h>
@interface UILabel (YRDropdownView)
+
- (void)sizeToFitFixedWidth:(CGFloat)fixedWidth;
+
@end
@implementation UILabel (YRDropdownView)
@@ -23,13 +25,18 @@ - (void)sizeToFitFixedWidth:(CGFloat)fixedWidth
self.numberOfLines = 0;
[self sizeToFit];
}
+
@end
@interface YRDropdownView ()
+
+- (CGGradientRef)backgroundGradient;
+
- (void)updateTitleLabel:(NSString *)newText;
- (void)updateDetailLabel:(NSString *)newText;
- (void)hideUsingAnimation:(NSNumber *)animated;
- (void)done;
+
@end
@@ -114,6 +121,7 @@ - (void)updateDetailLabel:(NSString *)newText {
#pragma mark - Initializers
+
- (id)init {
return [self initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
}
@@ -123,16 +131,15 @@ - (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
// Initialization code
+ _backgroundGradient = NULL;
self.titleText = nil;
self.detailText = nil;
self.minHeight = 44.0f;
-// self.backgroundImage = [UIImage imageNamed:@"bg-yellow.png"];
self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
titleLabel = [[UILabel alloc] initWithFrame:self.bounds];
detailLabel = [[UILabel alloc] initWithFrame:self.bounds];
backgroundImageView = [[UIImageView alloc] initWithFrame:self.bounds];
- backgroundImageView.image = [self.backgroundImage stretchableImageWithLeftCapWidth:1 topCapHeight:self.backgroundImage.size.height/2];
backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
accessoryImageView = [[UIImageView alloc] initWithFrame:self.bounds];
@@ -145,6 +152,16 @@ - (id)initWithFrame:(CGRect)frame
return self;
}
+#pragma mark - Memory Management
+
+- (void)dealloc
+{
+ if (_backgroundGradient) {
+ CGGradientRelease(_backgroundGradient);
+ }
+ [super dealloc];
+}
+
#pragma mark - Defines
#define HORIZONTAL_PADDING 15.0f
@@ -188,7 +205,7 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view
title:title
detail:detail
image:image
- backgroundImage:[UIImage imageNamed:@"bg-yellow.png"]
+ backgroundImage:nil
animated:animated
hideAfter:delay];
}
@@ -229,6 +246,7 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view
YRDropdownView *dropdown = [[YRDropdownView alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width, 44)];
currentDropdown = dropdown;
dropdown.titleText = title;
+ dropdown.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
if (detail) {
dropdown.detailText = detail;
@@ -240,8 +258,6 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view
if (backgroundImage) {
dropdown.backgroundImage = backgroundImage;
- } else {
- dropdown.backgroundImage = [UIImage imageNamed:@"bg-yellow.png"];
}
if (titleLabelColor) {
@@ -263,7 +279,7 @@ + (YRDropdownView *)showDropdownInView:(UIView *)view
[view addSubview:dropdown];
[dropdown show:animated];
- if (delay != 0.0) {
+ if (delay > 0.0) {
[dropdown performSelector:@selector(hideUsingAnimation:) withObject:[NSNumber numberWithBool:animated] afterDelay:delay+ANIMATION_DURATION];
}
@@ -305,8 +321,7 @@ + (BOOL)hideDropdownInView:(UIView *)view animated:(BOOL)animated
YRDropdownView *dropdown = (YRDropdownView *)viewToRemove;
[dropdown hideUsingAnimation:[NSNumber numberWithBool:animated]];
return YES;
- }
- else {
+ } else {
return NO;
}
}
@@ -358,8 +373,7 @@ - (void)hideUsingAnimation:(NSNumber *)animated {
[self done];
}
}];
- }
- else {
+ } else {
self.alpha = 0.0f;
[self done];
}
@@ -388,13 +402,13 @@ - (void)layoutSubviews {
CGColorRef color = [titleLabel.textColor CGColor];
const CGFloat *components = CGColorGetComponents(color);
float total = 0.0;
- for (int i = 0; i < (int)CGColorGetNumberOfComponents(color)-1; i++){
+ for (int i = 0; i < (int)CGColorGetNumberOfComponents(color)-1; i++) {
total += components[i];
}
if ((total/((int)CGColorGetNumberOfComponents(color)-1)) > 0.5){
titleLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.25];
titleLabel.shadowOffset = CGSizeMake(0, -1/[[UIScreen mainScreen] scale]);
- }else {
+ } else {
titleLabel.shadowColor = [UIColor colorWithWhite:1 alpha:0.35];
titleLabel.shadowOffset = CGSizeMake(0, 1/[[UIScreen mainScreen] scale]);
}
@@ -426,7 +440,7 @@ - (void)layoutSubviews {
if ((total/((int)CGColorGetNumberOfComponents(color)-1)) > 0.5){
detailLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.25];
detailLabel.shadowOffset = CGSizeMake(0, -1/[[UIScreen mainScreen] scale]);
- }else {
+ } else {
detailLabel.shadowColor = [UIColor colorWithWhite:1 alpha:0.35];
detailLabel.shadowOffset = CGSizeMake(0, 1/[[UIScreen mainScreen] scale]);
}
@@ -484,11 +498,35 @@ - (void)layoutSubviews {
[self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, dropdownHeight)];
- [backgroundImageView setImage:[backgroundImage stretchableImageWithLeftCapWidth:1 topCapHeight:backgroundImage.size.height/2]];
- [backgroundImageView setFrame:self.bounds];
-
+ if (self.backgroundImage) {
+ backgroundImageView.image = [self.backgroundImage stretchableImageWithLeftCapWidth:1 topCapHeight:self.backgroundImage.size.height/2];
+ backgroundImageView.frame = self.bounds;
+ }
}
-@end
+#pragma mark - Draw Methods
+
+- (CGGradientRef)backgroundGradient {
+ if (NULL == _backgroundGradient) {
+ CGFloat colors[16] = {255.0 / 255.0, 228.0 / 255.0, 137.0 / 255.0, 1.0,
+ 242.0 / 255.0, 203.0 / 255.0, 71.0 / 255.0, 1.0,
+ 241.0 / 255.0, 211.0 / 255.0, 108.0 / 255.0, 1.0,
+ 197.0 / 255.0, 157.0 / 255.0, 19.0 / 255.0, 1.0
+ };
+ CGFloat colorStops[4] = {0.0, 0.85, 0.95, 1.0};
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ _backgroundGradient = CGGradientCreateWithColorComponents(colorSpace, colors, colorStops, 4);
+ CGColorSpaceRelease(colorSpace);
+ }
+ return _backgroundGradient;
+}
+- (void)drawRect:(CGRect)rect {
+ CGContextRef ctx = UIGraphicsGetCurrentContext();
+
+ CGPoint startPoint = {0.0, 0.0};
+ CGPoint endPoint = {0.0, self.bounds.size.height};
+ CGContextDrawLinearGradient(ctx, [self backgroundGradient], startPoint, endPoint, 0);
+}
+@end
View
BIN  YRDropdownView/bg-yellow.png
Deleted file not rendered
View
BIN  YRDropdownView/bg-yellow@2x.png
Deleted file not rendered
Something went wrong with that request. Please try again.