开发者

UIButton's Custom image and frame

I have the following code.

  UIImage *cancelImg = [UIImage imageNamed:@"cancel.jpeg"]; 
  UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
  btnCancel.userInteractionEnabled = YES;
  [btnCancel setFrame:CGRectMake(0.0,0.0, 28.0, 28.0)];
  [btnCancel setImage:cancelImg forState:UIControlStateNormal];
  cell.accessoryView  = btnCancel;

cancel.jpeg currently is bigger than 28 x 28 and it's actually 100 x 100.

开发者_Python百科Why does the button display 100 x 100 size of the image when I've set the UIButton's size to 28 x 28?


The image of the button will not be rescaled. Set as the backgroundImage if you need rescaling.

[btnCancel setBackgroundImage:cancelImg forState:UIControlStateNormal];


This behaviour must have changed since, because the above code produces a scaled down button on iOS 4.2.


I've been experimenting in iOS 5 with custom buttons that autoresize when the device orientation changes. I set both a backgroundImage and an image, with the same initial bounds as the button, and what I see is that the backgroundImage resizes and the image does not, but remains centered in the button's frame.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜