2012-01-16 59 views
0

我在桌面视图中制作了一个iPad应用程序,其中名为crollTableView的tableView我在每行的单元格中创建两个标签,其名称为capitalLabel和stateLabel在人像模式,无法在横向模式下增加UILabel的宽度

现在我想提高我在横向模式下标签的宽度,

这里是代码片段,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

if(tableView==crollTableView){ 
     static NSString *[email protected]"Cell"; 
     static NSInteger StateTag = 1; 
     static NSInteger CapitalTag = 2; 
     UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if(cell == nil){ 

      // cell.backgroundColor=[UIColor yellowColor]; 
      cell=[[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease]; 
      CGRect frame; 
      frame.origin.x = 0; 
      frame.origin.y = 0; 
      frame.size.height = 70; 
      frame.size.width = 650; 


      UILabel *capitalLabel = [[UILabel alloc] initWithFrame:frame]; 
      capitalLabel.tag = CapitalTag; 
      capitalLabel.opaque = FALSE; 
      capitalLabel.font=[UIFont systemFontOfSize:20.0]; 
      [cell.contentView addSubview:capitalLabel]; 


      frame.origin.x += 680; 
      UILabel *stateLabel = [[UILabel alloc] initWithFrame:frame]; 
      stateLabel.tag = StateTag; 
      stateLabel.font=[UIFont systemFontOfSize:17.0]; 
      [cell.contentView addSubview:stateLabel]; 
     } 

     UILabel* capitalLabel = (UILabel *) [cell.contentView viewWithTag:CapitalTag]; 
     UILabel* stateLabel = (UILabel *) [cell.contentView viewWithTag:StateTag]; 

     capitalLabel.text=[news2 objectAtIndex:indexPath.row]; 
     stateLabel.text = [news3 objectAtIndex:indexPath.row]; 

     capitalLabel.backgroundColor = [UIColor clearColor]; 
     stateLabel.backgroundColor = [UIColor clearColor]; 

     capitalLabel.textColor=[UIColor whiteColor]; 
     stateLabel.textColor=[UIColor whiteColor]; 

     if(count<[news3 count]){ 
      capitalLabel.numberOfLines = 0; 
      [capitalLabel sizeToFit]; 

      stateLabel.numberOfLines = 0; 
      [stateLabel sizeToFit]; 

     }count++; 

     return cell; 
    } 
} 

我应该在我的代码做什么样的变化?

+0

你必须检查第一取向之后,你可以根据自己的定位来设置标签的大小。 – Hiren 2012-01-16 06:55:25

回答

1

您应该重写

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

通过检查条件的电流方向是横向还是纵向,您可以相应地设置标签的框架。

+0

它工作!!!!!! – GAMA 2012-01-19 10:29:15

1

尝试设置autoresizingMask到要自动缩放视图:

if (cell == nil)标签alloc+init后添加:

capitalLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 

stateLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
1

iOS中不关心增加宽度的任何控制时变化方向..只需将2个标签的autoresizing mask属性设置为UIViewAutoresizingFlexibleWidth ..这意味着您的控件的宽度将根据超级视图框的大小而改变。

0

尝试设置autoResizingMask,以便在方向更改期间视图会自动调整自身。

您可以更改Xcode尺寸检查器中的值。

enter image description here