> On 19 May 2016, at 04:47, Rick Mann <[email protected]> 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 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]