Re: Adding Padding To The ‘left’ of a Text Field.
Re: Adding Padding To The ‘left’ of a Text Field.
- Subject: Re: Adding Padding To The ‘left’ of a Text Field.
- From: Shlok Datye <email@hidden>
- Date: Fri, 7 Aug 2009 10:00:21 +0000
You can subclass NSTextFieldCell as in the following code, and apply
it to your text field in Interace Builder.
----------------------------------------
// The header file
#import <Cocoa/Cocoa.h>
@interface CustomTextFieldCell : NSTextFieldCell
{
}
@end
// The implementation file
#import "CustomTextFieldCell.h"
#define kLeftMargin 10.0
@implementation CustomTextFieldCell
- (void)drawInteriorWithFrame:(NSRect)cellFrame
inView:(NSView *)controlView
{
cellFrame.origin.x += kLeftMargin;
cellFrame.size.width -= kLeftMargin;
[super drawInteriorWithFrame:cellFrame
inView:controlView];
}
- (void)selectWithFrame:(NSRect)aRect
inView:(NSView *)controlView
editor:(NSText *)textObj
delegate:(id)anObject
start:(NSInteger)selStart
length:(NSInteger)selLength
{
aRect.origin.x += kLeftMargin;
aRect.size.width -= kLeftMargin;
[super selectWithFrame:aRect
inView:controlView
editor:textObj
delegate:anObject
start:selStart
length:selLength];
}
- (NSRect)_focusRingFrameForFrame:(NSRect)frame
cellFrame:(NSRect)cellFrame
{
return [[self controlView] bounds];
}
@end
----------------------------------------
Note that the last method (that takes care of properly displaying the
focus ring) should probably not be relied upon too much, for obvious
reasons. Anyone know of alternatives?
Shlok Datye
Coding Turtle
http://codingturtle.com
On 07.08.2009, at 07:18, Joshua Garnham wrote:
I have a text field with a background but to make it look right the
text
field needs to have some padding (or a slight indent) on the left
side of it a bit like the
NSSearchField (because of the search image). How would I give the
text field some padding on the left?
Thanks,
Josh.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden