Cocoa开发:文本处理、视图操作与开发要点
文本排列与居中显示
在视图中,文本块的排列可通过对齐方式、行间距和缩进等属性来实现。以下是在属性字符串中实现文本居中的示例代码:
[[NSColor colorWithDeviceRed: 168.0 / 255.0
green: 128.0 / 255.0
blue: 0.0 / 255.0
alpha: 255.0 / 255.0] set];
NSRectFill ( self.bounds );
NSString* text = @"Centered Text.";
NSMutableDictionary* attributes = [NSMutableDictionary dictionary];
[attributes setObject: [NSFont fontWithName:@"Helvetica" size:85.0]
forKey: NSFontAttributeName];
[attributes setObject: [NSColor yellowColor]
forKey: NSForegroundColorAttributeName];
// center text with paragraph style.
NSMutableParagraphStyle* centerStyle = [[NSMutableParagraphStyle alloc] init];
超级会员免费看
订阅专栏 解锁全文
5

被折叠的 条评论
为什么被折叠?



