• 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: Set font on NSTextView that uses bindings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Set font on NSTextView that uses bindings?


  • Subject: Re: Set font on NSTextView that uses bindings?
  • From: Jonathan Mitchell <email@hidden>
  • Date: Thu, 19 May 2016 10:42:43 +0100

> On 19 May 2016, at 04:47, Rick Mann <email@hidden> wrote:
>
> I seem to be unable to set the font used in an NSTextView that uses bindings to set the text content. The property it's bound to creates a plain NSString (no attributes).
>
> I've tried setting the font, setting the typing attributes, setting the font on textStorage, all to no avail.
>
> Any ideas? Thanks.
>
Try setting the text field to allow rich text.
Or use the attributedString binding to bind your string and use a value transformer to add in the required text attributes.
I find that I can get a lot more flexibility from my bindings by building them in code.

I use the block based transformer shown below to build ad hoc transformers.
You could do the same thing to do you attributed string conversion.
The beauty about using this block approach is that you can capture any other dependencies need for the transformation.
This can great increase the bindings scope.

eg:

    BPBlockValueTransformer *blockValueTransformer = [BPBlockValueTransformer valueTransformerWithBlock:^id(NSNumber *gender)  {
        return [gender integerValue] == BPGenderUnknown ? @NO : @YES;
    }];
    [self.genderPromptImageView bind:NSHiddenBinding toObject:self withKeyPath:@"employee.gender"
                             options:@{NSValueTransformerBindingOption: blockValueTransformer}];

The transformer class:
=================

@interface BPBlockValueTransformer : NSValueTransformer

+ (instancetype)valueTransformerWithBlock:(id(^)(id value))block;
@property (nonatomic,strong) id (^transform)(id value);

@end

@implementation BPBlockValueTransformer

+ (instancetype)valueTransformerWithBlock:(id(^)(id value))block
{
    BPBlockValueTransformer *transformer = [[self alloc] init];
    transformer.transform = block;

    return transformer;
}

+ (Class)transformedValueClass
{
    return [NSObject class];
}

- (id)transformedValue:(id)value
{
    return self.transform(value);
}

@end

J


_______________________________________________

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: 
 >Set font on NSTextView that uses bindings? (From: Rick Mann <email@hidden>)

  • Prev by Date: Set font on NSTextView that uses bindings?
  • Next by Date: Re: Set font on NSTextView that uses bindings?
  • Previous by thread: Set font on NSTextView that uses bindings?
  • Next by thread: Re: Set font on NSTextView that uses bindings?
  • Index(es):
    • Date
    • Thread