这是我作为iOS开发人员的第二天工作。到目前为止,我非常喜欢编码目标-C。我怎样才能让我的1线标签在父母的中心,同时在顶部?中心顶级标签iOS Objective-C
我迄今所做的:
- 学会了如何运用字体大小和字体颜色。通过编程学习了解如何创建ui。学会了向ui添加标签。
- 居中标签,如在父母的中心。
- 设置标签numberOfLines 0
这里是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// loading the viewcontroller, load the controllers/objects.
// set background and title of the view
[self.view setBackgroundColor:RGB(19,181,234)];
self.title = @"UI Main";
// add the label1
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 200, 40)];
[myLabel setBackgroundColor:[UIColor clearColor]];
myLabel.textColor = RGB(255,255,255);
[myLabel setText:@"Enter Amount"];
myLabel.numberOfLines = 0;
[myLabel setFont:[UIFont fontWithName:@"DejaVu Sans" size:10]];
[myLabel sizeToFit];
[[self view] addSubview:myLabel];
// [myLabel release];
}
这里是我的我的模拟器截图:http://i.stack.imgur.com/AN2JX.png
编辑:我的问题是关于让大小我的父母看法,以便我可以集中我的控制。但它已经得到了答复!谢谢!
的[如何中心一个UILabel可能重复在UIView](http://stackoverflow.com/questions/6753794/how-to-center-a-uilabel-on-uiview) –
set ** [self.label setCenter:CGPointMake(view.frame.size.width/2,view.frame.size.height/2)] ** –
谢谢安布。你的解决方案与下面的答案完全一样,但我理解Saheb的回答比你的回答更好。再次感谢! – user5295097