• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: switching text field between editable and non-editable
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >switching text field between editable and non-editable (From: "J.E. Schotsman" <email@hidden>)
 >Re: switching text field between editable and non-editable (From: Ken Thomases <email@hidden>)

  • Prev by Date: KVO - deallocation with observers attached
  • Next by Date: Re: KVO - deallocation with observers attached
  • Previous by thread: Re: switching text field between editable and non-editable
  • Next by thread: KVO - deallocation with observers attached
  • Index(es):
    • Date
    • Thread