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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:47:30+00:00 2026-06-14T03:47:30+00:00

I would like to create a custom class by subclassing the UIView that would

  • 0

I would like to create a custom class by subclassing the UIView that would look like the one below:
My target

Oh and the text says the body view should be 80px tall, its 50px.
But I cant seem to get it right. I have the class header prepared like so:

#import <UIKit/UIKit.h>

@interface MessageView : UIView

@property (strong, nonatomic)UIImage *backgroundImage;
@property (strong, nonatomic)UITextView *messageView;
@property (strong, nonatomic)UILabel *titleLabel;

- (id)initWithBackgroundImage:(NSString*)background;

- (void)setTitle:(NSString*)titleMessage;
- (void)setBody:(NSString*)bodyMessage;

@end

Now I will create these views by calling initWithBackgroundImage where I will pass the background image file name. The example shows one of these images. How do I implement the init method so that init will create a body like on the example except the texts will be empty?

My futile attempt of the init method was this:

- (id)initWithBackgroundImage:(NSString*)background
{
    self = [super init];//[super initWithFrame:CGRectMake(0, 0, 270, 100)];
    if (self)
    {
        backgroundImage = [[UIImage imageNamed:background] retain];
        messageView = [[UITextView alloc] initWithFrame:CGRectMake(10, 40, 250, 50)];
        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 20)];
    }
    return self;
}

But nothing happened. When done I will set the text via setter methods. And I would like to set the position on the final view via setCenter(x, y). I want the class to have “fixed” width and height.

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-14T03:47:31+00:00Added an answer on June 14, 2026 at 3:47 am

    EDIT:

       - (id)initWithBackgroundImage:(NSString*)background
        {
            self = [super init];//[super initWithFrame:CGRectMake(0, 0, 270, 100)];
            if (self)
            {
                UIImageView *bg  = [[UIImageView alloc] initWithImage:[UIImage imageNamed:background]];      
                messageView = [[UITextView alloc] initWithFrame:CGRectMake(10, 40, 250, 50)];
                titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 20)];
                [self addSubview:bg];
                [bg release];
                [self addSubview:messageView];
                [messageView release];
                [self addSubview:titleLabel];
                [titleLabel release];
            }
            return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom view that I would like to create from a resource
i would like to create a custom View (subclass of the View class) and
I have authored some custom classes that I would like to create using XAML:
I would like create a custom DataRow that will have -let's say- a propery
I would like to create a custom task that is called in a fashion
I would like to create a repoze custom predicate checker that is capable to
I would like to create a set of custom controls that are basically image
I would like to create a custom field in django that models an ordinary
In .NET 3.5, I would like to create a custom attribute (say [NetDataMember]) that
In my symfony application I would like to create custom php class. And access

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.