如何将表格单元格按钮对齐而不是右对齐?下面是我用来创建UIButton的代码。感谢。
cell.accessoryView = [self getButton: @"icon.png"];
...
- (UIButton*)getButton: (NSString*)icon {
UIImage *image = (true) ? [UIImage imageNamed:icon] : [UIImage imageNamed:icon];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
return button;
}
答案 0 :(得分:0)
您正在将按钮添加为附件视图,该视图无法放在左侧。看到这个问题,几乎完全一样:
答案 1 :(得分:0)
然后你可以用按钮的框架捣碎。
UIButton *cellButton = [self getButton:@"icon.png"];
[cell.contentView addSubview:cellButton];