我想将NSTextAlignmentCenter添加到以下属性。怎么样?
[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])];
答案 0 :(得分:0)
制作NSMutableParagraphStyle
,将其alignment
属性设置为NSTextAlignmentCenter,然后将其添加到以NSParagraphStyleAttributeName
为键的属性dict中。