firstButton is a UIButton of type Custom. I\'m programmatically putting three of them across each cell of a table, thusly:
[firstButton setImage:markImage fo
Only solution which worked for me:
[button setImage:image forState:UIControlStateNormal];
button.imageView.contentMode = UIViewContentModeScaleAspectFill;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
Found a fix for this. Set the adjustsImageWhenHighlighted
property of UIButton
to NO
.
UIButton *b = [[UIButton alloc] initWithFrame:rect];
[b setImage:image forState:UIControlStateNormal];
[b.imageView setContentMode:UIViewContentModeScaleAspectFill];
[b setAdjustsImageWhenHighlighted:NO];
Hope this helps. Feel free to comment below, I will follow up on any questions that you have.
Swift 3
self.firstButton.imageView?.contentMode = .scaleAspectFill
Instead of setImage try setBackgroundImage