我试图让我的按钮与我的自定义uitableviewcell完全相同的宽度和高度。
以下是我试图做的事情
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if (indexPath.row == 0) {
return cellCode;
}
if (indexPath.row == 1) {
cellManufacture.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cellManufacture;
}
if (indexPath.row == 2) {
cellModel.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cellModel;
}
if (indexPath.row == 3) {
cellYear.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cellYear;
}
}
submitButton.frame = cellSubmit.bounds; //<<<<<<HERE IS WHERE I SET SIZING :)
return cellSubmit;
}
然而这是我得到的结果....
答案 0 :(得分:0)
如何在UIButton中使用表格页脚视图?
CGSize buttonSize = CGSizeMake(300, 45);
CGRect viewRect = CGRectMake(0, 0, self.view.frame.size.width, buttonSize.height);
CGRect buttonRect = CGRectMake((viewRect.size.width-buttonSize.width) / 2 ,
(viewRect.size.height-buttonSize.height) / 2 ,
buttonSize.width,
buttonSize.height);
UIView *footerView = [[UIView alloc] initWithFrame: viewRect];
footerView.backgroundColor = [UIColor clearColor];
UIButton *submitButton = [UIButton buttonWithType: UIButtonTypeRoundedRect];
submitButton.frame = buttonRect;
[submitButton setTitle:@"SUBMIT" forState:UIControlStateNormal];
[footerView addSubview: submitButton];
[(UITableView *)self.view setTableFooterView: footerView];
[footerView release];
但是,如果你想要完全相同的外观,你应该在下一节中使用默认的UITableCell(UITableViewCellStyleDefault),而不是UIButton。
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text = @"SUBMIT";
cell.textLabel.textAlignment = UITextAlignmentCenter;