Objective c 如何在属性中添加NSTextAlignmentCenter?
我想将NSTextAlignmentCenter添加到以下属性。怎么做Objective c 如何在属性中添加NSTextAlignmentCenter?,objective-c,macos,Objective C,Macos,我想将NSTextAlignmentCenter添加到以下属性。怎么做 [nssWord drawInRect:CGRectMake(200, 200, 500, 200) withAttributes: @{ NSFontAttributeName : [NSFont fontWithName:@"Arial Black" size:100.0] }]; 试过这个。。。除了展示文本,什么都没有: NSMutableAttributedString *string = [[NSMutable
[nssWord drawInRect:CGRectMake(200, 200, 500, 200) withAttributes: @{ NSFontAttributeName : [NSFont fontWithName:@"Arial Black" size:100.0] }];
试过这个。。。除了展示文本,什么都没有:
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:nssWord];
[string drawInRect:CGRectMake(200, 200, 500, 200)];
[string addAttribute:NSFontAttributeName
value:[NSFont fontWithName:@"Arial Black" size:100.0]
range:NSMakeRange(0, [nssWord length])];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
[string addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [nssWord length])];
制作一个
NSMutableParagraphStyle
,将其alignment
属性设置为NSTextAlignmentCenter,然后将其添加到属性dict中,并将NSParagraphStyleAttributeName
作为键。我添加了另一个选项。。。但是problems@jdl伙计。在完成属性配置之前,您正在绘制字符串。