Camsoft
Camsoft

Reputation: 12005

NSControl's setCellClass is deprecated in OS X 10.10 what's the alternative for overriding NSTextField's cell class?

I'm attempting to follow the post linked below to override the NSCell of a NSTextField but it looks like the setCellClass method is now deprecated in OSX 10.10.

How to make NSTextField use custom subclass of NSTextFieldCell?

How should one override the NSTextField's cell substituting it for a subclass?

The reason for doing this is to vertically centre the text of a NSTextField cell which Apple have made very difficult.

Upvotes: 18

Views: 1221

Answers (2)

freya
freya

Reputation: 479

public override class var cellClass: AnyClass? { get { YourCustomCell.self } set {} }

on the NSControl subclass seems to work.

Upvotes: 1

Ssswift
Ssswift

Reputation: 1037

The short answer is: don't. As per the release notes, NSCell itself is being 'gradually deprecated'.

To vertically align some text, you can use layout constraints. Depending on the situation, you might need to put the NSTextField inside a larger NSView.

Upvotes: 0

Related Questions