私の目標は、グループ化されたtableviewのセルに挿入することです。iPadのfacebookやskype loginのように、それを完全に埋めるボタンです。これを行うには、私はこのコードを使用しますuibuttonでUITableCellViewを塗りつぶす
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Login";
UITableViewCell* cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.section == 1 && indexPath.row == 0){
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:cell.frame];
[button setTitle:@"Do Stuff" forState:UIControlStateNormal];
[cell addSubview:button];
}
return cell;
}
をしかし、結果はこれです:
ボタンがセルよりも広く、かつその位置が間違っている、私が欲しかったものではありません。 ボタンのフレームに適切な値を見つけるためにさまざまなテストを行いましたが、これは最高で最も洗練されたソリューションではないと思います。誰かが私より優れたソリューションを持っていますか?このコードの代わりに
:
if(indexPath.section == 1 && indexPath.row == 0){
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:cell.bounds];//note here bounds
[button setTitle:@"Do Stuff" forState:UIControlStateNormal];
[cell.contentView addSubview:button];
}
return cell;
結果は次のとおりです。ここで
ボタンの左上の頂点はセルの頂点と一致しますが、セルよりもまだ大きいです。私の質問では、イメージをもっと意味のあるものに変えました。 – LuckyStarr
pls post as image最終結果として必要なもの –
このコードをコピーするだけで –