HogeViewController.h
@interface HogeViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
IBOutlet UITableView* _itemTable;
UIButton *roundedButtonType;
}
@property (nonatomic, retain)IBOutlet UITableView *_itemTable;
@property (nonatomic, retain, readonly) UIButton *roundedButtonType;
HogeViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self._itemTable dequeueReusableCellWithIdentifier:@"hogeCell"];
if (cell == nil) {
CGRect frame = CGRectMake(0, 0, 300, 44);
cell = [[[UITableViewCell alloc] initWithFrame:frame
reuseIdentifier:@"hogeCell"] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.font = [UIFont systemFontOfSize:14];
}
UIButton *button = [self roundedButtonType];
[cell.contentView addSubview:button];
}
- (UIButton *)roundedButtonType
{
if (roundedButtonType == nil)
{
// create a UIButton (UIButtonTypeRoundedRect)
roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
roundedButtonType.frame = CGRectMake(198.0, 5.0, 97.0, 35.0);
[roundedButtonType setTitle:@"設定" forState:UIControlStateNormal];
roundedButtonType.backgroundColor = [UIColor clearColor];
[roundedButtonType addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
roundedButtonType.tag = 1; // tag this view for later so we can remove it from recycled table cells
}
return roundedButtonType;
}
参考:Apple iPhone Dev Center提供サンプルソース/UICatalog
タグ:iPhone
【UIButtonの最新記事】