как получить uibutton точно такой же ширины и высоты - PullRequest
0 голосов
/ 02 июня 2011

Я пытаюсь сделать так, чтобы моя кнопка была точно такой же ширины и высоты, что и моя пользовательская ячейка uitableview.

Вот как я пытаюсь это сделать

// 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

1 Ответ

0 голосов
/ 02 июня 2011

Как насчет использования представления нижнего колонтитула таблицы с 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;
...