OS X Lion 10.7.5, Xcode 4.6.3, Document based app for OS X. The title states my 
problem.
NOTE: IB is not used for anything other than a default empty nib. Views etc are 
all done programmatically. 
The 3 x 3 matrix is displayed with the attributed titles  and alternates but 
left aligned. 
I am unable to change this behaviour

However if I use the setTitle and setAlternateTitle methods (using strings 
instead of attributed strings) everything works.
I had hoped to use italic AlternateTitles hence the code below but which does 
not centre align the title in the Cell.

I'd appreciate any help in telling me where I've misunderstood or coded badly.  
Thanks. Peter

My Cell sub-class of NSButtonCell init method does the following:

- (id)init {
    self = [super init];
    if (self) {
        // Set the cell attributes
,,,,,
        [self setAlignment:NSCenterTextAlignment]; // <=== NOTE
        
        // Set the Cell title & alternate title
        
        NSFont *font = [NSFont fontWithName:@"Helvetica Neue" size:64.0];
        NSDictionary *attr = [NSDictionary dictionaryWithObject:font 
forKey:NSFontAttributeName];
        NSAttributedString *aTitle = [[NSAttributedString 
alloc]initWithString:@"XY"attributes:attr];
        [self setAttributedTitle:aTitle];

        NSFont *iFont = [NSFont fontWithName:@"Helvetica Neue Italic" 
size:64.0];
        NSDictionary *iAttr = [NSDictionary dictionaryWithObject:iFont 
forKey:NSFontAttributeName];
       NSAttributedString * iAtitle = [[NSAttributedString 
alloc]initWithString:@"AB"attributes:iAttr];
        [self setAttributedAlternateTitle:iAtitle];
    }
    return self;
}

The initialized Cell is used as the prototype for initializing my Matrix 
sub-class of NSMatrix:
This is done in the Document.m method windowControllerDidLoadNib
// Other prep stuff
----
    // Create the Matrix and set it's attributes
    Cell *protoCell = [Cell new]; // temp for initing the matrix
    _theMatrix = [[Matrix alloc]initWithFrame:theMatrixFrame 
mode:NSListModeMatrix prototype:protoCell
        numberOfRows:3 numberOfColumns:3];
// Set various attributes
-----
    [_theMatrix setAlignment:NSCenterTextAlignment];
    [theContentView addSubview:_theMatrix];


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to