【发布时间】:2011-10-18 12:13:00
【问题描述】:
我有一个视图,我正在以编程方式创建一个 UILabel 并将其称为我的参数传递,因为我需要许多具有不同位置框架的 UILabel 文本,所以我通过参数传递来调用它。
使用下面的代码,当我旋转到横向模式时,纵向视图标签仍然出现。我该如何克服呢?我需要在下面的代码中完成。我希望将标签框的位置从纵向视图更改为横向视图。
注意:我需要创建很多标签,大约 15 到 20 个,所以我使用参数传递,这样我就不需要为创建每个标签编写尽可能多的方法。
-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[UIFont fontWithName:@"Arial" size:13];
myLabel.text = labelTitle;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self.view addSubview:[self createLabel:CGRectMake(450,140,60,20):@"Ratings:"]];
[self.view addSubview:[self createLabel:CGRectMake(450,170,60,20):@"Reviews:"]];
}
else
{
[self.view addSubview:[self createLabel:CGRectMake(650,140,60,20):@"Ratings:"]];
[self.view addSubview:[self createLabel:CGRectMake(650,170,60,20):@"Reviews:"]];
}
return YES;
}
【问题讨论】:
标签: iphone objective-c ios