2011-06-02 95 views
-1

我想让我的按钮是完全相同的宽度和高度作为我的自定义uitableviewcell。如何让uibutton完全相同的宽度和高度的自定义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; 
} 

不过这是结果我得到.... enter image description here

+0

这是如何'cellSubmit'创建? – 2011-06-02 04:26:20

回答

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]; 

但是,如果你想完全一样的外观,你应该使用在下一节中,而不是UIButton的默认UITableCell(UITableViewCellStyleDefault)。

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease]; 
cell.textLabel.text = @"SUBMIT"; 
cell.textLabel.textAlignment = UITextAlignmentCenter; 
相关问题