Ios 为什么tableview单元格文本不随方向而改变,而单元格高度却随方向而改变
我的代码如下:Ios 为什么tableview单元格文本不随方向而改变,而单元格高度却随方向而改变,ios,uitableview,uiinterfaceorientation,landscape-portrait,Ios,Uitableview,Uiinterfaceorientation,Landscape Portrait,我的代码如下: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Color Cell" forIndexPath:indexPath]; ......
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Color Cell" forIndexPath:indexPath];
......
......
......
if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:14.0f];
} else {
cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:24.0f];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat rowHeight;
if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
rowHeight = ([[UIScreen mainScreen] bounds].size.width - 52) / [colorArray count];
} else {
rowHeight = ([[UIScreen mainScreen] bounds].size.height - 64) / [colorArray count];
}
return rowHeight;
}
当运行它时,表格视图可以自动正确地重新定向,单元格高度也可以。但单元格文本大小不会相应地改变
为什么??如何修复它
左边是肖像画,右边是风景画
UITableViewCell
在设备中更改方向时不重新加载,在更改方向后重新加载表格视图字体大小似乎减小了。我认为在横向模式下,单元格高度和字体大小的比例是不正确的。只需进一步减小字体大小。不,纵向和横向中的文本大小完全相同,不随方向而改变。只有细胞高度有影响。我添加了一个比较快照。您在IB中设置了最小字体大小吗?尝试过了,甚至设置了比代码中设置的最小字体大小(9磅)更小的字体大小(14磅)。但是没有改变。你是说self.tableView重新加载数据?放在哪里?添加self.tableView在更改方向时重新加载数据。将其添加到viewDidLoad
或(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
,或其他?-(void)将旋转到InterfaceOrientation:(UIInterfaceOrientation)到InterfaceOrientation持续时间:(NSTimeInterval)持续时间{if(端口右侧){//reload action;}否则{//reload action;}}