[英]iOS UITableView cell's custom separator doesn't change its width on landscape
I have my UITableView and have set my cell's separator. 我有UITableView并设置了单元格的分隔符。 Everything seems fine, but my separator doesn't change its width on landscape.
一切似乎都很好,但我的分隔符没有改变其在景观上的宽度。 Here is how it looks:
外观如下:
Here is the code where I create my custom cell: 这是我创建自定义单元格的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ListCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.backgroundColor = UIColor.clearColor;
}
//set cell's image and texts
...
UIView *separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 1)];
separatorLineView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
[cell.contentView addSubview:separatorLineView];
[cell layoutIfNeeded];
return cell;
}
Any ideas, how can I solve this problem? 有什么想法,我该如何解决这个问题?
Add separator line property in ListCell.h- 在ListCell.h-中添加分隔线属性
@property (strong, nonatomic) UIView *separatorLineView;
Try to replace separator line's code with following code - 尝试用以下代码替换分隔线的代码-
int screenHeight;
if ( [[UIApplication sharedApplication] statusBarOrientation] != UIInterfaceOrientationPortrait
&& [[UIApplication sharedApplication ]statusBarOrientation] != UIInterfaceOrientationPortraitUpsideDown){
screenHeight = [UIScreen mainScreen].applicationFrame.size.width;
} else {
screenHeight = [UIScreen mainScreen].applicationFrame.size.height;
}
if(cell.separatorLineView.superview == NULL){
cell.separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenHeight, 1)];
cell.separatorLineView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
[cell.contentView addSubview:cell.separatorLineView];
[cell layoutIfNeeded];
}
I will definitely work! 我一定会工作!
Or you can add separator line by storyboard- 或者,您可以按故事板添加分隔线-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.