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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:52:37+00:00 2026-06-12T21:52:37+00:00

I have an app which contains a pretty large form. I subclassed UILabel so

  • 0

I have an app which contains a pretty large form. I subclassed UILabel so I could have consistency in the form labels. However, a few of the labels are going to be section dividers with a background color and they’ll require an indent.

I know I can over ride the UILabel’s indent setting when it instantiates by using this code:

- (void)drawTextInRect:(CGRect)rect {
    UIEdgeInsets insets = {0, 5, 0, 5};
    return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}

but that’ll add insets to all of the labels. Not what I want.

So what I did was wrote a custom method:

- (void) makeInsets
{
    CGRect rect = self.frame;

    if (hasInset) {
        UIEdgeInsets insets = {0, 5, 0, 5};
        return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
    } else {
        UIEdgeInsets insets = {0, 0, 0, 0};
        return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
    }
}

Problem with that is it happens after the UILabel is drawn. I tried [UILabelSubclass setNeedsDisplay:YES] but get a “No visible interface” error for the setNeedsDisplay method. Is there a way I can override the existing inset with my custom ones?

  • 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-12T21:52:38+00:00Added an answer on June 12, 2026 at 9:52 pm

    Since you’re subclassing it… can’t you just add a boolean property to indicate whether or not to indent?

    .h file

    @property BOOL indentText;
    

    .m file

    - (id) initWithIndent:(BOOL)indent {
    
        if((self = [super init])) {
            self.indentText = indent;
        }
    
        return self;
    }
    
    - (void)drawTextInRect:(CGRect)rect {
    
        if( self.indentText ) {
            UIEdgeInsets insets = {0, 5, 0, 5};
            return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
        }
    }
    

    If you’re planning on having a lot of customizations then you could pass some sort of style constant in when you’re create the label to indicate how to mark it up… but if all you plan to do is this then I would just add a simple property to toggle it on.

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

Sidebar

Related Questions

I've created an app which contains form and that have to filled up in
I have a very simple Core Data app which pretty much contains strings of
I have an app which contains a scrollview with several tableviews. Each tableview is
I have a need for a model(?) on my app which basically contains a
I have an object which contains models for my ASP.NET MVC web app. The
I have CoreData in my app, with an Entry class, which contains an NSOrderedSet
in my winforms app, I have a Queue which contains objects: Queue<MyObj> _queuedRows =
I have a J2EE app deployed as an EAR file, which in turn contains
We have created a facebook-app which contains a fb:comment field. We have included the
I have a basic map view in my app which contains a set of

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.