Ввод кнопки в нижнем колонтитуле таблицы - PullRequest
3 голосов
/ 14 июля 2011

Я создаю пользовательскую кнопку и помещаю ее в нижний колонтитул моей таблицы, но кнопка выходит из правого угла.

Что здесь не так!?!

Вот мой код и выходное изображение:

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [aButton setTitleColor:[UIColor colorWithWhite:0.0 alpha:0.56] forState:UIControlStateDisabled];
    [aButton setBackgroundImage:[[UIImage imageNamed:@"test.png"] stretchableImageWithLeftCapWidth:kButtonSliceWidth topCapHeight:0] forState:UIControlStateNormal];
    [aButton setTitle:@"Click me" forState:UIControlStateNormal];
    [aButton.titleLabel setFont:[UIFont boldSystemFontOfSize:kFontSize14]];
    [aButton setFrame:CGRectMake(10.0, 15.0, 300.0, 44.0)];
    [self.tableView setTableFooterView:aButton];

enter image description here

Ответы [ 3 ]

15 голосов
/ 14 июля 2011

Я добавил кнопку в UIView, а затем установил tableFooterView для этого объекта UIView, и это сработало. Мы не можем напрямую поместить UIButton как tableFooterView.

0 голосов
/ 01 августа 2012

Одно важное дополнение к хорошему ответу Леголаса: вам нужно реализовать метод делегата tableView:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    foot 50;
}

Это сводило меня с ума, потому что кнопка (или, в моем случае, кнопки) не реагировали на событие касания. Добавление метода делегата сделало все это лучше. : -)

0 голосов
/ 14 июля 2011

Попробуйте сделать так. Установите IBOutlet UIView *footerView; и синтезируйте его. Добавьте его как подпредставление, используя метод-

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

if(footerView == nil) {
    //allocate the view if it doesn't exist yet
    footerView  = [[UIView alloc] init];


    //create the button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [button setFrame:CGRectMake(10, 3, 300, 44)];

    //set title, font size and font color
    [button setTitle:@"Click Me" forState:UIControlStateNormal];
    [button.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];

    //set action of the button
    [button addTarget:self action:@selector(clickPressed:)
     forControlEvents:UIControlEventTouchUpInside];

    //add the button to the view
    [footerView addSubview:button];
}

//return the view for the footer
return footerView;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...