Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8796623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:39:57+00:00 2026-06-13T23:39:57+00:00

I have made a simple subclass of UIView which has a few subviews but

  • 0

I have made a simple subclass of UIView which has a few subviews but its breaking for a reason I can’t see.

In my storyboard view controller I have added a UIView and made it the shape I want it, and added my custom class to it. The contents of my subclass is below:

@implementation PersonDetailCell

@synthesize button, requiredMarker, textField;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

    }
    return self;
}

-(void)layoutSubviews
{
    [self setBackgroundColor:[UIColor colorWithRed:87.0f/255.0f green:153.0f/255.0f blue:191.0f/255.0f alpha:1.0f]];

    textField = [[DetailTextField alloc] initWithFrame:CGRectMake(10, 0, self.frame.size.width -20, self.frame.size.height)];
    [textField setFont:[UIFont fontWithName:@"Helvetica" size:14.0f]];
    [textField setTextColor:[UIColor whiteColor]];
    [textField setHidden:YES];
    [self addSubview:textField];

    button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setHidden:YES];
    [self addSubview:button];

    requiredMarker = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 4, 22)];
    [requiredMarker setBackgroundColor:[UIColor redColor]];
    [requiredMarker setHidden:YES];
    [self addSubview:requiredMarker];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

Then in my view controller code I have imported my subclass and hooked up an IBOutlet of it to my view in my storyboard. In my viewDidLoad of my view controller I also try setting background colour of this view but nothing happens.

All of my code runs without crashing, but my issues:

  1. I can’t set the background colour from my view controller, (or any other properties for that matter).

  2. When I run the app, the height is more than that I set in my storyboard (width is fine), but I change the height of the view nowhere.

Any ideas? Am i using the wrong approach somehow?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:39:58+00:00Added an answer on June 13, 2026 at 11:39 pm

    If it is a table cell, then the class should be extending UITableViewCell. Buttons and textfields can be added on the storyboard – then you can use struts and springs (Size Inspector pane) to ensure the view resizes properly. I don’t think layoutSubviews should be used for adding new UI elements (maybe for resizing if you need to do it manually).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made multiple simple but fun apps for iPhone in the past few
I have made a simple code for ajax to call a page but it
I have made a simple Line Chart: Which is showing 4 grid-lines at points
I have made a simple timer app which update a textview every second. I
I have made a simple chat script using jquery and AJAX but the huge
I have made a simple tic tac toe app for Android which needs no
I have made a simple fragment of html, which contains this: <a href=#><div>Something here</div></a>
I have made simple cocoa touch apps before but I have never used UINavigationControllers,
I have made a simple username/password dialog to which I want to apply a
I have made a simple realtime visitor counter. You can download it from this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.