Skip to content

Instantly share code, notes, and snippets.

@ananfang
Created February 3, 2012 10:18
Show Gist options
  • Save ananfang/1729514 to your computer and use it in GitHub Desktop.
Save ananfang/1729514 to your computer and use it in GitHub Desktop.
Load nib file as GUI component
//
// CustomView.h
//
// Created by Fang Andy on 12/2/3.
// Copyright (c) 2012年 Openmouse Studio. All rights reserved.
//
#import <UIKit/UIKit.h>
#define UPLOADING_WORDING @"Uploading %i photo(s)..."
@interface CustomView : UIView
@property (nonatomic, weak) IBOutlet UIActivityIndicatorView *activityIndicatorView;
@property (nonatomic, weak) IBOutlet UILabel *uploadingLabel;
@end
//
// CustomView.m
//
// Created by Fang Andy on 12/2/3.
// Copyright (c) 2012年 Openmouse Studio. All rights reserved.
//
#import "CustomView.h"
@implementation CustomView
@synthesize activityIndicatorView = _activityIndicatorView;
@synthesize uploadingLabel = _uploadingLabel;
@end
//
// ViewController.h
//
// Created by Fang Andy on 12/1/18.
// Copyright (c) 2012年 Openmouse Studio. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
//
// ViewController.m
//
// Created by Fang Andy on 12/1/18.
// Copyright (c) 2012年 Openmouse Studio. All rights reserved.
//
#import "ViewController.h"
#import "CustomView.h"
@implementation ViewController
#pragma mark - View lifecycle
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSArray *xibViews = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil];
CustomView *customView = nil;
for (id subXib in xibViews) {
if ([subXib isMemberOfClass:[CustomView class]]) {
customView = subXib;
}
}
[self.view addSubview:customView];
[customView.activityIndicatorView startAnimating];
customView.uploadingLabel.text = [NSString stringWithFormat:UPLOADING_WORDING, 2];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment