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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:23:54+00:00 2026-05-30T19:23:54+00:00

I have a custom background for an UITextField . But the first 20 pixels

  • 0

I have a custom background for an UITextField. But the first 20 pixels of the UITextField are taken by the design. The text should start 30 pixels from the left. I have searched quite a bit, but I couldn’t find it. I have seen things like overriding properties, but is that really necessary for something this basic?

  • 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-30T19:23:55+00:00Added an answer on May 30, 2026 at 7:23 pm

    I’ve seen two different solutions:

    • add an empty UIView as a leftView property of UITextView
    • subclass UITextField, and override methods textRectForBounds: editingRectForBounds: – just return frame with insets applied

    IMHO the second one is more elegant.

    Example:
    .h:

    #import <UIKit/UIKit.h>
    
    @interface BlackTextField : UITextField
    
    @property (nonatomic, assign) CGFloat paddingRight, paddingTop, paddingLeft, paddingBottom;
    @end
    

    .m:

    #import "BlackTextField.h"
    #import <QuartzCore/QuartzCore.h>
    
    @implementation BlackTextField
    @synthesize paddingTop, paddingBottom, paddingLeft, paddingRight;
    
    - (id)initWithCoder:(NSCoder *)coder {
        self = [super initWithCoder:coder];
        if (self) {        
            self.paddingRight   = 10;
            self.paddingLeft    = 10;
            self.paddingTop     = 5;
            self.paddingBottom  = 5;        
        }
        return self;
    }
    
    - (CGRect)textRectForBounds:(CGRect)bounds 
    {
        return CGRectMake(bounds.origin.x + self.paddingLeft, bounds.origin.y + self.paddingTop, bounds.size.width - self.paddingLeft - self.paddingRight, bounds.size.height - self.paddingTop - self.paddingBottom);
    }
    
    - (CGRect)editingRectForBounds:(CGRect)bounds 
    {
        return [self textRectForBounds:bounds];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITextField with a custom background, but now i want to change
Possible Duplicate: custom UITextField with image as a background blinking cursor issue I have
Background have a custom UITableCellView in which I'm using a custom UITextField that I've
I have a dialog that resizes. It also has a custom background which I
The background is I have a custom control that is a asp:Menu that is
Background I have a custom collection that is binded to the datagridview this.datagridview.DataSource =
I have custom errors configured in my web.config, but IIS 6.0 is returning the
i am confused with custom background image in section. i have set an custom
I have a custom ViewGroup (blue background) that when touched sometime during the app's
I have an app that has a custom background for a UITableView . Up

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.