如何在点击按钮方法的Uiimageview上设置按钮图像?

时间:2015-02-13 10:04:57

标签: ios uiimageview uibutton

我想在UIButton的点击方法中在UIImageview.image中设置UIButton背景图像的图像。

-(void)Click_save:(UIButton *)sender
{
    UIButton *btn = sender;
    UIView *view  = [[UIView alloc] initWithFrame:CGRectMake(10, 60, 320, 600)];
    [self.view addSubview:view];
    UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 300, 600)];
    [view addSubview:imgview];

    imgview.image = btn.imageView.image;
 }

1 个答案:

答案 0 :(得分:1)

您需要使用imageView的image属性而不是backgroundColor属性。您还需要使用按钮的imageForState:属性来获取图像。

使用:

 imgview.image = [btn imageForState:UIControlStateNormal];