我有一个自定义 UIView,我需要将其添加到父 View Controller ,但自定义 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
最佳答案
self.backgroundColor = [UIColor colorWithRed:56 green:56 blue:57 alpha:1.0f];
等于:
self.backgroundColor = [UIColor whiteColor];
试试这个!
self.backgroundColor = [UIColor colorWithRed:56.f/255 green:56.f/255 blue:57.f/255 alpha:1.0f];
关于ios - Objective-c,将自定义 UIView 添加到父 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25550891/