Padding the textfields

Most of the programmer knows the basic concepts of Objective c. But the “Happy Coding” going to do they describe about “what is the scenario achieved By “Happy Coding” in the platform. That have posted here.
Any Clarification on that, Kindly Comment it.

Add Padding in the textfields.

  • Use “Category” file  to achieve the padding and cursor position pointing.
  • Create a UITextfield category file (.h and .m).

Create Category file from Xcode.

  1. File → New → File… or use ⌘N.
  2. Select Objective-C File.Screen Shot 2017-04-06 at 6.30.56 PM

 

  1. Type in category name, select File Type: Category, and then select the base class.Screen Shot 2017-04-06 at 6.31.27 PM

 

.h file

#import <UIKit/UIKit.h>

@interface UITextField (mytextFiled)

- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;

@end

.m file

#import "UITextField+mytextFiled.h"

@implementation UITextField (mytextFiled)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
- (CGRect)textRectForBounds:(CGRect)bounds {
    
    return CGRectMake(bounds.origin.x + 10, bounds.origin.y,
                      bounds.size.width - 10, bounds.size.height - 0);
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
    return [self textRectForBounds:bounds];
}

@end

After creating the text field in the view controllers then will check the padding is added on the every text field.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s