0
我有一個自定義UIView,我需要添加到父視圖控制器但自定義UIView沒有顯示。Objective-c,添加一個自定義UIView到父視圖控制器
//
// ViewController.m
// InstantForum
//
// Created by trikam patel on 27/08/2014.
// Copyright (c) 2014 trikam patel. All rights reserved.
//
#import "ViewController.h"
#import <FacebookSDK/FacebookSDK.h>
@interface ViewController()
@end
@implementation ViewController
@synthesize loginSignupControlView;
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
self.loginSignupControlView = [[LoginSignupControlView alloc] initWithFrame:CGRectMake(0, 0, 320, 68)];
[self.view addSubview:self.loginSignupControlView];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// LoginSignupControlView.m
// InstantForum
//
// Created by trikam patel on 28/08/2014.
// Copyright (c) 2014 trikam patel. All rights reserved.
//
#import "LoginSignupControlView.h"
@implementation LoginSignupControlView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createView];
// Initialization code
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self createView];
}
return self;
}
-(void)createView{
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
self.backgroundColor = [UIColor colorWithRed:56 green:56 blue:57 alpha:1.0f];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
謝謝@Nicolas Bonnet – redoc01 2014-08-28 14:44:38