IBDesignable - custom button image stretches when shouldn't
| Originator: | openradar.rond | ||
| Number: | rdar://20200137 | Date Originated: | 3/17/15 |
| Status: | Open | Resolved: | |
| Product: | Xcode | Product Version: | 6.1.1; 6.3b3 |
| Classification: | Developer Tools | Reproducible: | Always |
Summary:
In an IBDesignable subclass of UIButton, when calling setImage: programmatically …
if the frame size in IB is set larger than the image, it STRETCHES when it shouldn’t. (Button background images stretch; foreground images don’t.)
Sample code, from subclass "CustomButton : UIButton”:
IB_DESIGNABLE
@interface CustomButton ()
@property (nonatomic, strong) IBInspectable NSString *buttonStyle;
@end
-(void)setButtonStyle:(NSString *)styleName {
if ([styleName isEqualToString:@“play"]) {
UIImage *foregroundImage = [UIImage imageNamed:(@“icon-play")
inBundle:[NSBundle bundleForClass:[self class]]
compatibleWithTraitCollection:nil];
[self setImage:foregroundImage forState:UIControlStateNormal];
}
}
Steps to Reproduce:
In Interface Builder:
- Add a “Button” from the Object library to a view controller’s view
- Change its Class to a custom subclass containing the IBInspectable code below
- Add a graphic asset by the referenced name (and consisting of an image something *other* than blue) to the project’s Images.xcassets
- In IB’s Attributes Inspector, change the Button Style to the string value referenced in the code
- Stretch the frame of the button in the canvas to larger than the icon’s actual size
- Once IBDesignable updates, observe that the image is displayed stretched, when it shouldn’t be
[Please see attached images. Note that the tinting of the image is a separate issue (#20200040). To work around it temporarily, type in a dummy string value for the ‘image’ property in the Attributes inspector, then re-expand the button’s frame size in the canvas.]
Expected Results:
The image should align in the same way foreground images normally do (incl. how it does at runtime) — and NOT stretch.
Version:
OS X 10.9.5, Xcode 6.1.1; OS X 10.10.2, Xcode 6.3b3
Attachments:
'button-image-stretch1a.png' and 'button-image-stretch1b.png' were successfully uploaded.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!