简体   繁体   中英

can't change button width in tableFooterView

here is the code

- (void)viewDidLoad
{
    hauptOptionen = [[NSMutableArray alloc] init];
    self.hauptOptionen = [NSMutableArray arrayWithCapacity:7];

    [hauptOptionen addObject:@"Welchen Beruf übern Sie aus?"];
    [hauptOptionen addObject:@"In Welcher Alterstufe sind Sie?"];
    [hauptOptionen addObject:@"Wo liegt Ihr Unternehmen?"];
    [hauptOptionen addObject:@"Wieviel Beschäftigte hat Ihr Unternehmen?"];
    [hauptOptionen addObject:@"Bekommen Sie ein 13. Gehalt?"];
    [hauptOptionen addObject:@"Bekommen Sie ein 14. Gehalt?"];
    [hauptOptionen addObject:@"Wieviele Überstunden machen Sie im Monat?"];

    UIButton *berechnenButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    berechnenButton.frame = CGRectMake(10, 0, 90, 40); 
    [berechnenButton setTitle:@"Berechnen!" forState:UIControlStateNormal];
    [berechnenButton addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventTouchUpInside];
    //[myView addSubview:closeButton];

    kategorienAuswahl = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
    kategorienAuswahl.delegate = self;
    kategorienAuswahl.dataSource = self;
    kategorienAuswahl.autoresizesSubviews = YES;
    kategorienAuswahl.tableFooterView = berechnenButton;

    self.view = kategorienAuswahl;

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

but the button is too large

在此处输入图像描述

You should really add the button to a "backing view". Just make a new UIView , add the button to it, and then set the table's footer view to the new UIView .

You should not add it as a button. Add it as a UIView , and have that button as a subView in that UIView.

or Just implement the

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM