在UIControlEventTouchUpInside操作上将更改按钮图像添加到UITableView标头

时间:2017-05-25 08:25:13

标签: ios uibutton uiimage uitableviewsectionheader

我在UITableView标题

中创建了一个带有不同状态图像的按钮
  -(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {

        self.filterButton = [UIButton buttonWithType:UIButtonTypeCustom];

        [self.filterButton setBackgroundImage:[UIImage imageNamed:@"g29_fctn_filter_default"] forState:UIControlStateNormal];
        [self.filterButton setBackgroundImage:[UIImage imageNamed:@"g31_fctn_filter_applied"] forState:UIControlStateSelected];
        [self.filterButton setBackgroundImage:[UIImage imageNamed:@"g30_fctn_filter_active"] forState:UIControlStateHighlighted];

        self.filterButton.frame = CGRectMake((self.myTableView.frame.size.width / 2) - 60, 10, 44, 32);
        [self.filterButton addTarget:self action:@selector(filterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        //imageView.contentMode = UIViewContentModeScaleAspectFit;
        [view addSubview:self.filterButton];
        return view;
    }

当我将按钮状态设置为以编程方式选择时,我看不到UIButton图像更改,它仍然显示为forState设置的图像:UIControlStateNormal

-(void) filterButtonPressed:(id)sender
{
   [self.filterButton setSelected:YES];
}

0 个答案:

没有答案