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:38:05 +0000
Well, in principle you can add "#define kTopMargin 1.0" at the top,
and into the cell methods add something like "cellFrame.origin.y +=
kTopMargin;" and "aRect.origin.y += kTopMargin;" However, this can
look awful if the text does not fit properly.
In any case, Graham's solution might be a much better one.
Shlok Datye
Coding Turtle
http://codingturtle.com
On 07.08.2009, at 10:08, Joshua Garnham wrote:
Thanks that works perfectly!
One question though, what code would I need to add to also give it
padding to the top of the text field?
Thanks Very Much,
Josh.
From: Shlok Datye <email@hidden>
To: Joshua Garnham <email@hidden>
Cc: Cocoa Developers <email@hidden>
Sent: Friday, 7 August, 2009 11:00:21
Subject: Re: Adding Padding To The ‘left’ of a Text Field.
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