Objective C で X-Code を使用して iPhone アプリを開発しています。テーブルの下部に青色のフッター (ヘッダーと同じ) を追加したいと考えています。
これをどのように達成できるかを提案するのを手伝ってくれる人はいますか。また、このフッターにボタンを追加する方法。
前もって感謝します。
Objective C で X-Code を使用して iPhone アプリを開発しています。テーブルの下部に青色のフッター (ヘッダーと同じ) を追加したいと考えています。
これをどのように達成できるかを提案するのを手伝ってくれる人はいますか。また、このフッターにボタンを追加する方法。
前もって感謝します。
これがお役に立てば幸いです
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[viewFotter setBackgroundColor:[UIColor blueColor]];
return viewFotter;
}
しかし、問題は、ボタンのサイズを変更できないことです。ボタンが機能しないためです。
このコードを.m
ファイルに貼り付けて、フッタービューに画像を追加することもできます
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 44;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
[viewFotter setBackgroundColor:[UIColor blueColor]];
UIButton *GoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[GoBtn setTitle:@"GO" forState:UIControlStateNormal];
GoBtn.frame = CGRectMake(85, 7, 150, 39 );
[GoBtn addTarget:self action:@selector(GOButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[viewFotter addSubview:GoBtn];
return viewFotter;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
footerView.backgroundColor =[UIColor blueColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:@"BUTTON" forState:UIControlStateNormal];
btn.frame = CGRectMake(100, 5, 100, 30 );
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:btn];
return footerView;
}
-(void) btnClicked:(id) sender{
//ur code
}
UIButton
必要なコンポーネント ( 、など) を含むカスタム ビューを作成しUIImageView
、必要な値を
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
または、同じビューを tableFooterView に割り当てることもできます
tableView.tableFooterView = yourBlueView;
UIButton
をxibのフッターにドラッグするだけでボタンを追加できUITableView
ますが、テーブルビューの幅に自動的に割り当てられるため、ボタンのサイズを変更することはできません。しかし、フッターの色について何を言っているのかわかりません。詳しく説明していただけますか。