ios - Objective-c,将自定义 UIView 添加到父 View Controller

标签 ios

我有一个自定义 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/

相关文章:

ios - 如何将透明PNG图像与颜色合并

iOS 绑定(bind)库不适用于模拟器,但可以在设备上使用

ios - UIPageViewController - 双击点区域显示部分过渡(Xcode 8、Swift 3)

ios - 从另一个类访问 IBOutlet 属性

ios - View Controller 状态栏在像 ios 8 这样的新 iPhone 中重叠

ios - 以编程方式创建时不显示导航 Controller

ios - iOS 中的 Core Bluetooth LE 和 Classical

ios - Apple - 如果密码更改,我们如何在 iOS 应用程序中使用 Touch ID

ios - Xcode 7.3 桥接 header 看不到其他 header

ios - 同时 CCActions Cocos2d