Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在属性中添加NSTextAlignmentCenter?_Objective C_Macos - Fatal编程技术网

Objective c 如何在属性中添加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

我想将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])];

制作一个
NSMutableParagraphStyle
,将其
alignment
属性设置为NSTextAlignmentCenter,然后将其添加到属性dict中,并将
NSParagraphStyleAttributeName
作为键。

我添加了另一个选项。。。但是problems@jdl伙计。在完成属性配置之前,您正在绘制
字符串。