0
我是iPad開發新手。在這裏,我有一個帶有動態內容的桌面視圖。每個單元格包含兩個標籤,第二個標籤可能增加或減少。最後,我將標籤添加到單元格。但是當我旋轉模擬器時,單元格中的標籤不會改變。我無法爲標籤設置框架。請幫幫我。如何在模擬器中旋轉iPad時設置標籤框架
在此先感謝。
UILabel *label1 = nil;
UILabel *label2 = nil;
NSLog(@"it decides the tablecell");
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"Cell"] autorelease];
label1 =[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 44) ];
//label1 = [[UILabel alloc] initWithFrame:CGRectZero];
[label1 setLineBreakMode:UILineBreakModeWordWrap];
[label1 setMinimumFontSize:FONT_SIZE];
[label1 setNumberOfLines:0];
[label1 setFont:[UIFont boldSystemFontOfSize:FONT_SIZE]];
label2 = [[UILabel alloc] initWithFrame:CGRectZero];
[label2 setMinimumFontSize:FONT_SIZE];
[label2 setNumberOfLines:0];
[label2 setLineBreakMode:UILineBreakModeWordWrap];
[label2 setFont:[UIFont systemFontOfSize:FONT_SIZE]];
}
NSString *text1 = [arrOutline1 objectAtIndex:[indexPath row]];
NSString *text2 = [arrOutline2 objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake((CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2))/ 2, 20000.0f);
CGSize size1 = [text1 sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGSize size2 = [text2 sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
[label1 setText:text1];
[label2 setText:text2];
[label1 setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN-10,(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2))/2, MAX(size1.height, 44.0f))];
NSLog(@"now it is in cell methd");
UIDeviceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
{
[label2 setFrame:CGRectMake(300 , CELL_CONTENT_MARGIN - 10,500 , MAX(size2.height, 44.0f))];
NSLog(@"orientation is :LAndscape");
//[[cell contentView] addSubview:label2];
[cell addSubview:label2];
}
else
{
NSLog(@"orientation is Portrait.");
[label2 setFrame:CGRectMake(300 , CELL_CONTENT_MARGIN - 10,200 , MAX(size2.height, 44.0f))];
[cell addSubview:label2];
}
//[label2 setFrame:CGRectMake(300 , CELL_CONTENT_MARGIN - 10,(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2)) /2 , MAX(size2.height, 44.0f))];
cellHeight =size2.height + 44;
label1.backgroundColor =[UIColor clearColor];
label2.backgroundColor =[UIColor clearColor];
[[cell contentView] addSubview:label1];
[label1 release];
[label2 release];
return cell;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[TableOutline reloadData];
return YES;
}