在横向中调整内容UITableviewcell的大小 [英] resizing content UITableviewcell in landscape
问题描述
我正在使用iPhone SDK开发应用程序,并且想在设备处于横向模式时调整tableviewcell的内容大小.
I'm developing an app in iPhone SDK and I want to resize the content of my tableviewcell when the device is in landscape mode.
在tableviewcell中,我有一个同步图像和两个标签.在纵向模式下,它看起来非常不错,但是当我横向移动设备时,表格视图的内容不会调整大小.
In my tableviewcell I have an synchronous image and two labels. In portrait mode it looks very nice, but when I turn the device in landscape the content of my tableview doesn't resize.
有人可以帮忙吗?
此代码用于ionterfaceOrientation
,如果它是横向视图,则将reloadData
调用到我的表视图中.
This code is for ionterfaceOrientation
and if this is in landscape I call the reloadData
to my tableview.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight)
{
NSLog(@"LandsCape Mode");
[mytabla reloadData];
}else{
NSLog(@"Portrait Mode");
}
return YES;
// for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在此之前一切正常,但我的表视图不会调整内容的大小.
Until this everything is OK, but my tableview does not resize content.
这是初始化表格cellForRowAtIndexPath:(NSIndexPath *)indexPath
AsyncImageView *asyncImageView = nil;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
CGRect frame;
frame.origin.x = 5;
frame.origin.y = 10;
frame.size.width = 70;
frame.size.height = 60;
asyncImageView = [[[AsyncImageView alloc] initWithFrame:frame] autorelease];
asyncImageView.tag = ASYNC_IMAGE_TAG;
cell.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
frame.origin.x = 52 + 10;
frame.size.width = 200;
NSString *urlSeccion = aBook.Titulo;
urlSeccion = [urlSeccion stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSString *SeccionSummary = aBook.Summary;
SeccionSummary = [SeccionSummary stringByReplacingOccurrencesOfString:@"\n" withString:@""];
[cell.contentView addSubview:asyncImageView];
upLabelText = [[UILabel alloc] initWithFrame:CGRectMake(90, cell.frame.origin.y, cell.frame.origin.size, 50)];
upLabelText.textColor = [UIColor blackColor];
upLabelText.text = urlSeccion;
[upLabelText setNumberOfLines:2];
[upLabelText setLineBreakMode:UILineBreakModeWordWrap];
upLabelText.font = [UIFont systemFontOfSize:13.0];
downLabelText = [[UILabel alloc] initWithFrame:CGRectMake(90, 45, cell.frame.origin.size, 50)];
downLabelText.textColor = [UIColor blackColor];
downLabelText.text = SeccionSummary;
[downLabelText setNumberOfLines:5];
[downLabelText setLineBreakMode:UILineBreakModeWordWrap];
downLabelText.font = [UIFont systemFontOfSize:8.0];
[cell.contentView addSubview:downLabelText];
[cell.contentView addSubview:upLabelText];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
asyncImageView = (AsyncImageView *) [cell.contentView viewWithTag:ASYNC_IMAGE_TAG];
NSString *urlSeccionImagen = aBook.ThumbnailURL;
urlSeccionImagen = [urlSeccionImagen stringByReplacingOccurrencesOfString:@" " withString:@""];
urlSeccionImagen = [urlSeccionImagen stringByReplacingOccurrencesOfString:@"\n" withString:@""];
urlSeccionImagen = [urlSeccionImagen stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *urlString = [NSString stringWithFormat:urlSeccionImagen,indexPath.row + 1];
NSURL *url = [NSURL URLWithString:urlString];
[asyncImageView loadImageFromURL:url];
return cell;
}
标签不响应调整大小,并且在表视图上有摆动.我在想的是重置表视图,但我不知道该怎么做.
The labels don't respond to the resize and there are swing over the tableview. What I'm thinking is to reset my tableview but I don't know how to do it.
推荐答案
感谢您的共享.具有设置UITableViewCell的方法是一个好主意.但是我发现uitableviewcell的内容可以仅使用以下代码行调整大小:
Thanks for this sharing. This is a great idea having a method to set-up the UITableViewCell. But I figured out that the content of a uitableviewcell can rezise with just this code line:
tituloLabelText.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
tituloLabelText.text = @"A Large text resides here";
[tituloLabelText setNumberOfLines:2];
[tituloLabelText setLineBreakMode:UILineBreakModeWordWrap];
仅需使用autoresizingMask这一行,即可让控件修改其Widht和Height.
With just the line of autoresizingMask this allow to the controlls modify their Widht and Height.
这篇关于在横向中调整内容UITableviewcell的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!