如何仅在水平而非垂直方向上将其父视图中的任何子视图居中.我尝试了child.center = parent.center但它将我的子视图水平和垂直放置在父视图的中心.我怎样才能将它在中心水平对齐.谢谢
希望你们所有人都没事.我的申请中有一点问题.我有自定义单元格的tableview.在我的定制单元课上,我做了一个uiview
UIView* cellView = [[UIView alloc] initWithFrame:self.contentView.frame];
cellView.backgroundColor = [UIColor grayColor];
[self.contentView addSubview:cellView];Run Code Online (Sandbox Code Playgroud)
- (SummaryViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cell";
SummaryViewCell *cell = (SummaryViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[SummaryViewCell alloc] init];
}
cell.backgroundColor = [UIColor blueColor];
return cell;
}Run Code Online (Sandbox Code Playgroud)
我已经尝试过initWithFrame:self.contentView.frame]但是同样的问题发生了(uiview出现在单元格中,但只覆盖了一半的单元格),我也尝试过cellView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self. frame.size.width和高度相同但是失败了.需要您宝贵的建议和想法.非常感谢.