
//create the vIEw and make it grayUIVIEw *vIEw = [[UIVIEw alloc] init];vIEw.backgroundcolor = [UIcolor darkGraycolor];//everything for labelUILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,42,21)];//set text of labelNsstring *welcomeMessage = [@"Welcome," stringByAppendingString:@"username"];welcomeMessage = [welcomeMessage stringByAppendingString:@"!"];label.text = welcomeMessage;//set colorlabel.backgroundcolor = [UIcolor darkGraycolor];label.textcolor = [UIcolor whitecolor];//propertIEslabel.textAlignment = NSTextAlignmentCenter;[label sizetoFit];//add the components to the vIEw[vIEw addSubvIEw: label];label.center = vIEw.center;//show the vIEwself.vIEw = vIEw;
line,label.center = vIEw.center;应将标签移动到视图的中心.但是将其移动到标签中心位于视图左侧角落的位置,如下所示.
screenshot http://gyazo.com/2d1c064a671e32c7eb004647232fa430.png
有谁知道为什么?
解决方法 您需要使用框架初始化视图:UIVIEw *vIEw = [[UIVIEw alloc] initWithFrame:self.vIEw.frame];总结
以上是内存溢出为你收集整理的ios – UILabel设置为视图中心全部内容,希望文章能够帮你解决ios – UILabel设置为视图中心所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)