在使用UITableViewCell的时候,特别是自定义的cell时,时常需要在cell上添加button,
方式一:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(270, self.timeLabel.frame.origin.y-20, 50, 30)];
button.backgroundColor = [UIColor blueColor];
button.enabled = YES;
[button setTitle:@"X" forState:UIControlStateNormal];
[button setTitle:@"V" forState:UIControlStateHighlighted];
[cell addSubview:button];
方式二:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(270, self.timeLabel.frame.origin.y-20, 50, 30)];
button.backgroundColor = [UIColor blueColor];
button.enabled = YES;
[button setTitle:@"X" forState:UIControlStateNormal];
[button setTitle:@"V" forState:UIControlStateHighlighted];
<