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 6156041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:32:34+00:00 2026-05-23T20:32:34+00:00

I have created the following subclass to do some custom drawing: // DocumentIconView.h @interface

  • 0

I have created the following subclass to do some custom drawing:

//  DocumentIconView.h

@interface DocumentIconView : UIView
{
    UIImageView     *documentIconView;
    CloseHandle     *closeHandle;
    UILabel         *filenameLabel;
}

@property (nonatomic, strong) UIImageView *documentIconView;
@property (nonatomic, strong) CloseHandle *closeHandle;
@property (nonatomic, strong) UILabel *filenameLabel;

+ (DocumentIconView *)documentIconWithFrame:(CGRect)viewFrame
                     previewImage:(UIImage *)previewImage
                            title:(NSString *)title;

This works well for the most part (I can instantiate objects, and do custom drawing), however, I cannot access some of its properties from another classes.

DocumentIconView *iconView = [DocumentIconView documentIconWithFrame:frame 
                                                      previewImage:[UIImage imageNamed:@"GenericDocumentIcon.png"] 
                                                             title:[NSString stringWithFormat:@"test"]];

iconView.backgroundColor = [UIColor lightGrayColor];  // this works
iconView.filenameLabel.backgroundColor = [UIColor darkGrayColor]; // this does not work - no error message
[documentsView addSubview:iconView];

I can read and write first-level properties, but cannot drill deeper; when trying to read properties, the value returned is (null)

I am fairly new at subclassing, so I think I am missing something really obvious here. Any help would be greatly appreciated.

EDIT: the method for instantiating the view in question:

+ (DocumentIconView *)documentIconWithFrame:(CGRect)viewFrame
                     previewImage:(UIImage *)previewImage
                            title:(NSString *)title
{
    DocumentIconView *view = [[DocumentIconView alloc] initWithFrame:viewFrame];

    // Close handle's size is assigned here
    CGSize closeHandleSize = CGSizeMake(27, 27);

    // The document preview image's frame is calculated by shrinking it by the close handle's size
    CGRect documentPreviewFrame = CGRectMake(closeHandleSize.width / 2, 
                                           closeHandleSize.height / 2, 
                                           viewFrame.size.width - closeHandleSize.width, 
                                             viewFrame.size.height - closeHandleSize.height - 20); // 20 points is the filenameLabel's height

    UIImageView *documentPreviewView = [[UIImageView alloc] initWithFrame:documentPreviewFrame];
    documentPreviewView.contentMode = UIViewContentModeScaleAspectFit;
    documentPreviewView.backgroundColor = [UIColor clearColor];
    documentPreviewView.image = previewImage;

    [view addSubview:documentPreviewView];

    CGRect closeHandleFrame = CGRectMake(0, 0, closeHandleSize.width, closeHandleSize.height);
    CloseHandle *closeHandleView = [[CloseHandle alloc] initWithFrame:closeHandleFrame];

    closeHandleView.alpha = 0.0;
    closeHandleView.tag = kCloseHandleTag;
    [view addSubview:closeHandleView];

    CGRect filenameFrame = CGRectMake(0, 
                                      viewFrame.size.height - 20, 
                                      viewFrame.size.width, 
                                      20);
    UILabel *filenameLabel = [[UILabel alloc] initWithFrame:filenameFrame];
    filenameLabel.backgroundColor = [UIColor clearColor];
    filenameLabel.text = title;
    filenameLabel.font = [UIFont boldSystemFontOfSize:17];
    filenameLabel.textColor = [UIColor whiteColor];
    filenameLabel.textAlignment = UITextAlignmentCenter; 
    [view addSubview:filenameLabel];

    view.tag = kDocumentIconTag;

    return view;
}
  • 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-05-23T20:32:35+00:00Added an answer on May 23, 2026 at 8:32 pm

    In your documentIconWithFrame:... method you’re using a local variable (filenameLabel) that you’re adding to the view. That means your instance variable is never instantiated and is always nil.

    Just change this:

    UILabel *filenameLabel = [[UILabel alloc] initWithFrame:filenameFrame];
    

    to this:

    filenameLabel = [[UILabel alloc] initWithFrame:filenameFrame];
    

    and the same for the other instance variables.

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

Sidebar

Related Questions

I have one subclass of NSManagedObject like following and stored some instances by NSManagedObjectContext.
I have a NSManagedObject subclass, created by the XCode model interface. This class has
I created a custom UIView subclass, and would prefer to not layout the UI
I have created a custom UIView that I would like to use on multiple
I have created customize UIView with following code .....it's running with no issue....but when
I have created following rule in the .htaccess file located at the root of
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have created the following C library for reading an image: typedef struct {
I have created the following project structure for my new asp.net mvc project any
I have created the following vsct file xml. <?xml version=1.0 encoding=utf-8?> <CommandTable xmlns=http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable xmlns:xs=http://www.w3.org/2001/XMLSchema>

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.