Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.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 Xcode 5中的文本对齐_Objective C_Text_Xcode5_Uilabel_Center - Fatal编程技术网

Objective c Xcode 5中的文本对齐

Objective c Xcode 5中的文本对齐,objective-c,text,xcode5,uilabel,center,Objective C,Text,Xcode5,Uilabel,Center,我的UILabel的代码: //Create the title of the tab here UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; title.text=@"Useful Websites"; title.textAlignment=UITextAlignmentCenter; [self.view addSubview:title]; 我知道iOS6不推荐使用a

我的UILabel的代码:

        //Create the title of the tab here
UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
title.text=@"Useful Websites";
title.textAlignment=UITextAlignmentCenter;
[self.view addSubview:title];
我知道iOS6不推荐使用assigner UITextAlignmentCenter。请您使用正确的赋值器/属性来将标签居中放置在Xcode 5和iOS7中,好吗?谢谢。

使用:

title.textAlignment = NSTextAlignmentCenter;

带nstext对齐的开关

title.textAlignment=NSTextAlignmentCenter;

当您在XCode中编写时,当您开始键入“title.textAlignment”时,您将看到一条提示,告诉您该属性接受哪种类型。在本例中,NSTEXTALIGNING。是否需要删除initWithFrame?它似乎弄乱了文本的对齐。这不应该影响它,是iPhone的吗?如果是这样的话,将其设置为500像素将超出屏幕范围。如果文本在标签上居中,它将显示在屏幕上,因为标签悬挂在边缘180像素。非常感谢。你是为数不多的真正帮助过我并真诚地帮助过我的人之一!这对我来说非常有效。我需要删除initWithFrame吗?它似乎弄乱了文本的对齐方式。initWithFrame init如果标签具有所需的宽度和高度,可以尝试其他尺寸。