Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added way of displaying empty (or error) message in the middle of the…

… CLCGVC screen
  • Loading branch information...
commit 3b546c61cf70a7ec29508ce313482331aa6cff14 1 parent aa011f7
@ettore authored
View
16 CLCGVC.h
@@ -36,6 +36,10 @@
UIActivityIndicatorView *mSpinner;
UIActivityIndicatorViewStyle mSpinnerStyle;
UIColor *mSpinnerBackgroundColor;
+
+ UIView *mEmptyContainer;
+ UILabel *mEmptyLabel;
+
id<CLCGPopoverContentDelegate> mPopoverContentDelegate;
}
@@ -43,9 +47,19 @@
@property(nonatomic,retain) IBOutlet UIActivityIndicatorView *spinner;
@property(nonatomic) UIActivityIndicatorViewStyle spinnerStyle;
@property(nonatomic,retain) UIColor *spinnerBackgroundColor;
+@property(nonatomic,retain) IBOutlet UIView *emptyContainer;
+@property(nonatomic,retain) IBOutlet UILabel *emptyLabel;
@property(nonatomic,assign) id<CLCGPopoverContentDelegate> popoverContentDelegate;
-/**
+
+/**
+ * If msg is non-nil, this method shows and aligns the given message to the
+ * center of the screen. Otherwise, it removes the message if it was displayed.
+ */
+-(void)showEmptyMessage:(NSString*)msg;
+
+
+/**
* If show == YES, shows and aligns the spinny indicator to the center
* of the screen.
* If show == NO, removes the spinny indicator if it was displayed, or do
View
63 CLCGVC.m
@@ -10,6 +10,7 @@
#import "clcg_gfx.h"
#import "clcg_viewport.h"
#import "UIViewCategory.h"
+#import "UILabelCategory.h"
#import "CLCGVC.h"
@@ -23,6 +24,8 @@ @implementation CLCGVC
@synthesize spinnerStyle = mSpinnerStyle;
@synthesize spinnerBackgroundColor = mSpinnerBackgroundColor;
@synthesize popoverContentDelegate = mPopoverContentDelegate;
+@synthesize emptyLabel = mEmptyLabel;
+@synthesize emptyContainer = mEmptyContainer;
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
@@ -59,10 +62,12 @@ -(void)createSpinnerView
}
--(void)centerSpinner
+-(void)centerSpinnerAndEmptyPlaceholder
{
[mSpinner centerVerticallyWithOffset:0];
[mSpinner centerHorizontally];
+ [mEmptyLabel centerVerticallyWithOffset:0];
+ [mEmptyLabel centerHorizontally];
}
@@ -77,7 +82,7 @@ -(void)showLoadingView:(BOOL)show
[mSpinnerContainer setNeedsLayout];
}
- [self centerSpinner];
+ [self centerSpinnerAndEmptyPlaceholder];
[mSpinner startAnimating];
[[self view] bringSubviewToFront:mSpinnerContainer];
} else {
@@ -91,7 +96,57 @@ -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)to_orie
duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:to_orient duration:duration];
- [self centerSpinner];
+ [self centerSpinnerAndEmptyPlaceholder];
+}
+
+
+//------------------------------------------------------------------------------
+#pragma mark - Empty Placeholder View
+
+
+-(void)createEmptyView
+{
+ UIView *cont;
+ UILabel *label;
+
+ label = [[UILabel alloc] initWithFrame:CGRectZero];
+ [self setEmptyLabel:label];
+ [label release];
+ [mEmptyLabel setTextColor:[UIColor darkGrayColor]];
+ [mEmptyLabel setFont:[UIFont systemFontOfSize:14]];
+ [mEmptyLabel setTextAlignment:NSTextAlignmentCenter];
+ [mEmptyLabel setLineBreakMode:NSLineBreakByWordWrapping];
+ [mEmptyLabel setNumberOfLines:0];//use as many lines as needed
+
+ cont = [[UIView alloc] initWithFrame:[[self view] frame]];
+ [cont setBackgroundColor:[UIColor whiteColor]];
+ [cont setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
+ [cont addSubview:mEmptyLabel];
+ [self setEmptyContainer:cont];
+ [cont release];
+}
+
+
+-(void)showEmptyMessage:(NSString*)msg
+{
+ if (msg) {
+ UIView *mainview = [self view];
+
+ if (![[mainview subviews] containsObject:mEmptyContainer]) {
+ if (mEmptyContainer == nil)
+ [self createEmptyView];
+
+ [mEmptyLabel setText:msg];
+ [mEmptyLabel sizeToFitWidth:([mainview w] - DEFAULT_PADDING*2)];
+ [mainview addSubview:mEmptyContainer];
+ [mEmptyContainer setNeedsLayout];
+ }
+
+ [self centerSpinnerAndEmptyPlaceholder];
+ [mainview bringSubviewToFront:mEmptyContainer];
+ } else {
+ clcg_safe_remove_from_superview(mEmptyContainer);
+ }
}
@@ -121,6 +176,8 @@ -(void)releaseRetainedSubviews
{
CLCG_REL(mSpinner);
CLCG_REL(mSpinnerContainer);
+ CLCG_REL(mEmptyLabel);
+ CLCG_REL(mEmptyContainer);
}
View
2  categories/UILabelCategory.h
@@ -9,4 +9,6 @@
-(void)resizeHeightForText;
+-(void)sizeToFitWidth:(CGFloat)w;
+
@end
View
16 categories/UILabelCategory.m
@@ -9,11 +9,27 @@
#import "UILabelCategory.h"
#import "UIViewCategory.h"
+
@implementation UILabel (Candygirl)
+
+-(void)sizeToFitWidth:(CGFloat)w
+{
+ CGSize sz;
+
+ sz = CGSizeMake(w, INT_MAX);
+ sz = [[self text] sizeWithFont:[self font] constrainedToSize:sz];
+
+ [self setW:sz.width];
+ [self setH:sz.height];
+}
+
+
-(void)resizeHeightForText
{
return [self resizeHeightForText:[self text] font:[self font]];
}
+
@end
+
View
3  clcg_viewport.h
@@ -28,6 +28,9 @@
#import <Foundation/Foundation.h>
+#define DEFAULT_PADDING 9.0f
+#define DEFAULT_PADDING_COMFORT 8.0f
+
#ifdef __cplusplus
extern "C" {
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.