我使用MFSideMenu来显示我的菜单项。但我不知道为什么它最终会让我看到黑线。
如何移除黑色部分。
这是最终出现的图像
我使用https://github.com/mikefrederick/MFSideMenu来整合MFSideMenu。
这是我的Sidemen代码
-(void) viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = CustomPinkColor;
MenuArray =[NSArray arrayWithObjects:@"Knects",@"Settings",@"Share",@"About",nil];
//tableView.backgroundColor = CustomPinkColor;
tableView.alwaysBounceVertical = NO;
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return MenuArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.backgroundColor=CustomPinkColor;
cell.textLabel.textColor=[UIColor blackColor];
}
cell.textLabel.text = [MenuArray objectAtIndex:indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *colorView = [[UIView alloc]init];
colorView.backgroundColor = CustomPinkColor;
return colorView;
}
答案 0 :(得分:2)
这是一个自动布局问题,这样你就可以解决这个问题:
步骤1:将此方法添加到MFSideMenuContainerViewController控制器
- (void)layoutContraintsforLeftView:(UIView*)view adjestToContainer:(UIView*)container {
if(!view) {
return;
}
view.translatesAutoresizingMaskIntoConstraints = NO;
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0]];
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:0.0]];
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0]];
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0]];
[view layoutIfNeeded];
}
- (void)layoutContraintsForRightView:(UIView*)view adjestToContainer:(UIView*)container {
if(!view) {
return;
}
view.translatesAutoresizingMaskIntoConstraints = NO;
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0]];
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeLeading
multiplier:1.0
constant:50.0]];
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeTrailing
multiplier:1.0
constant:0.0]];
[container addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:container
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0]];
[view layoutIfNeeded];
}
第2步:将方法- (void)setupMenuContainerView)
替换为此
- (void)setupMenuContainerView {
if(self.menuContainerView.superview) return;
self.menuContainerView.frame = self.view.bounds;
self.menuContainerView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view insertSubview:menuContainerView atIndex:0];
[self layoutContraintsforLeftView:menuContainerView adjestToContainer:self.view];
if(self.leftMenuViewController && !self.leftMenuViewController.view.superview) {
[self.menuContainerView addSubview:self.leftMenuViewController.view];
[self layoutContraintsforLeftView:self.leftMenuViewController.view adjestToContainer:menuContainerView];
}
if(self.rightMenuViewController && !self.rightMenuViewController.view.superview) {
[self.menuContainerView addSubview:self.rightMenuViewController.view];
[self layoutContraintsForRightView:self.rightMenuViewController.view adjestToContainer:menuContainerView];
}
}
第3步:现在已经完成了;运行你的代码。