Skip to content

Instantly share code, notes, and snippets.

@JigarM
Last active August 29, 2015 14:13
Show Gist options
  • Save JigarM/3bddd1902c6cbc553fcc to your computer and use it in GitHub Desktop.
Save JigarM/3bddd1902c6cbc553fcc to your computer and use it in GitHub Desktop.
Loading a custom UIView class with a custom nib file.
//Original Post : https://gist.github.com/leviathan/769539
#import "ProfileView.h"
ProfileView *myView = nil;
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:self options:nil];
for (id currentObject in nibViews) {
if ([currentObject isKindOfClass:[ProfileView class]]) {
myView = (ProfileView *) currentObject;
break;
}
}
//You can call the Method of ProfileView.m from here.
[myView configureView:@{
@"fullName" : @"Jigar Maheshwari",
@"email" : @"[email protected]",
@"profileImage" : @"sample.png"
}];
//
// ProfileView.h
// Jigar
//
// Created by Jigar on 31/12/14.
// Copyright (c) 2014 Jigar. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ProfileView : UIView
@property (weak, nonatomic) IBOutlet UIImageView *profileImage;
@property (weak, nonatomic) IBOutlet UILabel *email;
@property (weak, nonatomic) IBOutlet UILabel *fullName;
@property (weak, nonatomic) IBOutlet UIImageView *whiteLineSeperator;
- (void)configureView:(NSDictionary *)dict;
@end
//
// ProfileView.m
// Jigar
//
// Created by Jigar on 31/12/14.
// Copyright (c) 2014 Jigar. All rights reserved.
//
#import "ProfileView.h"
#import <QuartzCore/QuartzCore.h>
@implementation ProfileView
@synthesize profileImage;
@synthesize email;
@synthesize fullName;
@synthesize whiteLineSeperator;
- (void)configureView:(NSDictionary *)dict{
self.fullName.text = [dict objectForKey:@"fullName"];
self.email.text = [dict objectForKey:@"email"];
self.profileImage.image = [UIImage imageNamed:[dict objectForKey:@"profileImage"]];
self.profileImage.layer.cornerRadius = self.profileImage.frame.size.width / 2;
self.profileImage.clipsToBounds = YES;
self.profileImage.layer.borderWidth = 2.0f;
self.profileImage.layer.borderColor = [UIColor whiteColor].CGColor;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment