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

  • Home
  • SEARCH
  • 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 8777373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:15:50+00:00 2026-06-13T19:15:50+00:00

I made a subclass of UIButton, and I want to set a padding. I

  • 0

I made a subclass of UIButton, and I want to set a “padding”. I want the button’s frame to always be 15 pixels wider on each side, than the text.

In the drawRect method, I set the frame of the button to be 30 px wider than the text’s width. But when I try to do this the frame does not get adjusted at all. Is this frame getting adjusted after I change the frame of my uibutton? How can I adjust the frame to set a padding?

Here is my code:

- (void)drawRect:(CGRect)rect{
[self setBackgroundImage:[[UIImage imageNamed:@"submitBtn.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:0] forState:UIControlStateNormal];
[self setFrame:CGRectMake(rect.origin.x, rect.origin.y-90, self.titleLabel.frame.size.width + 30, self.frame.size.height)]; 
}

Thanks for the answers!!

  • 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-13T19:15:52+00:00Added an answer on June 13, 2026 at 7:15 pm

    You should override the setTitle:forState: method and adjust the frame there. You should also set the background image somewhere other than drawRect:. A good place would be the initXXX method.

    The only thing you should do in drawRect: is actually render content for the view based on its current state. No state should be changed in drawRect:.

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

Sidebar

Related Questions

I made of subclass of UIView called Bubble using which i want to draw
I made a UITableViewCell subclass, and now I want that subclass to be clever.
In my app, I made a subclass of UIView that I want to use
I made a subclass of UIImageView and I want to add something to be
I made a subclass of UIView that has a fixed frame. So, can I
I made a subclass of goog.ui.Button in my Google Closure javascript. /** * @fileoverview
I have made a UIViewController subclass without a .xib file, thinking I would not
I made a custom UITableView subclass and implemented this: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { //
I have subclass of UINavigationBar . @interface MyNavigationBar : UINavigationBar Made some changes and
I made an iphone app to capture image from camera and to set that

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.