Created
June 17, 2014 09:57
-
-
Save lukaskubanek/159c2df832dcee6aec03 to your computer and use it in GitHub Desktop.
Replacing the class to subclass after loading a custom view from Interface Builder
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
// | |
// CustomView.h | |
// IBSubclassTest | |
// | |
// Created by Lukas Kubanek on 17.06.2014. | |
// Copyright (c) 2014 Lukas Kubanek. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface CustomView : UIView | |
@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
// | |
// CustomView.m | |
// IBSubclassTest | |
// | |
// Created by Lukas Kubanek on 17.06.2014. | |
// Copyright (c) 2014 Lukas Kubanek. All rights reserved. | |
// | |
#import "CustomView.h" | |
#import "SubclassCustomView.h" | |
@implementation CustomView | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
self.backgroundColor = [UIColor redColor]; | |
} | |
return self; | |
} | |
- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder | |
{ | |
Class subclass = [SubclassCustomView class]; | |
return [[subclass alloc] initWithCoder:aDecoder]; | |
} | |
@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
// | |
// SubclassCustomView.h | |
// IBSubclassTest | |
// | |
// Created by Lukas Kubanek on 17.06.2014. | |
// Copyright (c) 2014 Lukas Kubanek. All rights reserved. | |
// | |
#import "CustomView.h" | |
@interface SubclassCustomView : CustomView | |
@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
// | |
// SubclassCustomView.m | |
// IBSubclassTest | |
// | |
// Created by Lukas Kubanek on 17.06.2014. | |
// Copyright (c) 2014 Lukas Kubanek. All rights reserved. | |
// | |
#import "SubclassCustomView.h" | |
@implementation SubclassCustomView | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
self = [super initWithCoder:aDecoder]; | |
if (self) { | |
self.backgroundColor = [UIColor blueColor]; | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment