> On 31 May 2017, at 21:13, Ken Thomases <[email protected]> wrote:
> 
> On May 31, 2017, at 1:51 PM, J.E. Schotsman <[email protected]> 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 protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to