我创建在其中,我创建NSTextField
编程这样的可可应用程序,的NSTextField垂直对齐
NSView *superView = [[NSView alloc] initWithFrame:NSMakeRect(0, 300, 1400, 500)];
NSTextField *myTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(180, 100, 1000, 300)];
[myTextField setStringValue:myText];
[myTextField setEditable:NO];
[myTextField setBezeled:NO];
[myTextField setDrawsBackground:NO];
[myTextField setSelectable:NO];
[myTextField setFont:[NSFont fontWithName:@"Futura" size:22]];
[superView addSubview:myTextField];
[superView setAutoresizesSubviews:YES];
[myTextField setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self.window.contentView addSubview:superView];
现在我想我的文字的垂直对齐,并应根据文本长度可调。
任何人有任何建议吗?请分享你的建议:)
非常感谢.. !!
谢谢sosborn .. !!让我试试这个..如果有任何问题,我会回复你。 :) – iUser 2012-04-18 08:21:14
好吧,我有'RSVerticallyCenteredTextFieldCell.h'和'RSVerticallyCenteredTextFieldCell.m'类,但我不知道如何使用它,用我的'myTextField'。 – iUser 2012-04-18 08:50:26
看看NSControl(从哪个NSTextField继承)。它有一个名为setCellClass的方法。 Apple的Control and Cell Programming Guide doc也很好阅读。 – sosborn 2012-04-18 08:57:05