-1

ボタンをカスタム 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;  
}

しかし、これは私が得る結果です.... ここに画像の説明を入力

4

1 に答える 1

0

UIButton で Table Footer View を使用するのはどうですか?

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;
于 2011-06-02T04:07:53.900 に答える