Re: switching text field between editable and non-editable
Re: switching text field between editable and non-editable
- Subject: Re: switching text field between editable and non-editable
- From: Jonathan Mitchell <email@hidden>
- Date: Wed, 31 May 2017 23:06:37 +0100
> On 31 May 2017, at 21:13, Ken Thomases <email@hidden> wrote:
>
> On May 31, 2017, at 1:51 PM, J.E. Schotsman <email@hidden> wrote:
>>
>> I have a hard time achieving what the message title says.
>> Depending on user settings I want a text field to be either editable or non-editable.
The following works for me.
@implementation NSTextField (CocoaDev)
- (void)bp_styleAsEditableTextField
{
[self setSelectable:YES];
[self setEditable:YES];
[self setDrawsBackground:YES];
[self setBezeled:YES];
[self.cell setScrollable:YES]; // required so that text scrolls horizontally when editing
[self.cell setWraps:NO];
[self.cell setLineBreakMode:NSLineBreakByWordWrapping]; // setting to truncate here kills the horiz scrolling during edit
[self setContentCompressionResistancePriority:1 forOrientation:NSLayoutConstraintOrientationHorizontal];
}
- (void)bp_styleAsEditableWrappingTextField
{
[self setSelectable:YES];
[self setEditable:YES];
[self setDrawsBackground:YES];
[self setBezeled:YES];
[self.cell setLineBreakMode:NSLineBreakByWordWrapping];
}
- (void)bp_styleAsLabel
{
[self setSelectable:NO];
[self setEditable:NO];
[self setDrawsBackground:NO];
[self setBezeled:NO];
[self.cell setLineBreakMode:NSLineBreakByTruncatingTail]; // truncate the tail
[self setContentCompressionResistancePriority:1 forOrientation:NSLayoutConstraintOrientationHorizontal];
}
- (void)bp_styleAsWrappingLabel
{
[self setSelectable:NO];
[self setEditable:NO];
[self setDrawsBackground:NO];
[self setBezeled:NO];
[self.cell setLineBreakMode:NSLineBreakByWordWrapping];
}
@end
_______________________________________________
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