我尝试使用此代码在按钮图像中设置alpha值:
UIImageView *imageTopView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"Top_80.png"]];
imageTopView.alpha = 0.5;
topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[topBtn addTarget:self action:@selector(btnRotatingObj:)
forControlEvents:UIControlEventTouchUpInside];
[topBtn setImage: imageTopView.image forState:UIControlStateNormal];
[topBtn setTitle:@"TOP" forState:UIControlStateNormal];
[self.view addSubview:topBtn];
它不起作用.....
答案 0 :(得分:0)
您正在使用图像视图的图像设置按钮的图像。您的图片视图的alpha值为0.5,但当然不是您的图片。
相反,请将图片视图添加为按钮的子视图:
[topBtn addSubView:imageTopView];