Question

I try this code for set the alpha value in button image:

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];

its not working.....

Was it helpful?

Solution

You are setting the image of the button with the image of your image view. Your image view has an alpha of 0.5, but of course not your image.

Instead, add the image view as a subview of your button:

[topBtn addSubView:imageTopView];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top