Setting UIButton image results in blue button in iOS 7

后端 未结 15 1742
[愿得一人]
[愿得一人] 2020-11-28 20:52

On iOS 6 SDK I wrote the following lines of code to display an image inside a button:

NSURL *thumbURL2 = [NSURL URLWithString:@\"http://example.com/thumbs/2.         


        
相关标签:
15条回答
  • 2020-11-28 21:10

    Old thread, but I wanted to chime in because I just had the same problem. The issue was just that you are calling setImage when you should call setBackgroundImage.

    0 讨论(0)
  • 2020-11-28 21:10

    making the tint color as clearcolor for all the four states(Default,Highlighted,selected,disabled) worked for me.

    0 讨论(0)
  • 2020-11-28 21:11

    In iOS7 there is new button type called UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // standard system button

    Check your .xib file and change button type to Custom Look at the image

    To do this programmatically, add this line to the viewDidLoad:

    [UIButton buttonWithType:UIButtonTypeSystem]; 
    
    0 讨论(0)
  • 2020-11-28 21:13

    There's a good chance that the image is there and you just can't see it. Try changing the button's type to UIButtonTypeCustom. If that doesn't work, set the button's background color to [UIColor clearColor];

    0 讨论(0)
  • 2020-11-28 21:13

    This Problem is called blue color problem of the button in xcode. When we make button by code the button shows the blue tint color by default.This can be solved byt assigning tint color to black or white accordingly to your cell's color. The code is :

    UIImage *closebtnimg = [UIImage imageNamed:@"icon_uncheck.png"];
     UIImage *closebtnimg1 = [UIImage imageNamed:@"icon_checked.png"];
    
    Custombutton *button = [Custombutton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(52, 66, 25, 24)];
    [button setBackgroundImage:closebtnimg forState:UIControlStateNormal];
    [button setBackgroundImage:closebtnimg1 forState:UIControlStateSelected];
    [button setTintColor:[UIColor whiteColor]];
    [cell.contentView addSubview:button];
    [button addTarget:self action:@selector(changeImage:)  forControlEvents:UIControlEventTouchUpInside];
    
    0 讨论(0)
  • 2020-11-28 21:15

    It seems iOS 7 is using the image provided just as an Alpha mask for displaying the button's tint color. Changing the button type to UIButtonTypeCustom did the trick for me (thanks user716216!). Setting the image as background doesn't always work if you already have a background image, as was my case.

    0 讨论(0)
提交回复
热议问题