UIButton缩小图像?
我正在使用iPad UI,并且该UI上的button需要具有此图像:
(作为PNG)。 button被声明如下:
CGRect newNoteButtonRect = CGRectMake(0, 0, 69, 43); UIButton* newNoteButton = [[UIButton alloc] initWithFrame:newNoteButtonRect]; newNoteButton.imageView.contentMode = UIViewContentModeScaleToFill; [newNoteButton setImage:self.fNewNoteIcon forState:UIControlStateNormal];
其中'fNewNoteIcon'是一个UIImage。 当用户界面出现时,图像是微小的和挤压的,几乎没有什么可以改变这一点。 有任何想法吗?
图标初始化如下:
self.fNewNoteIcon = [UIImage imageNamed:@"New_Note.png"];
在提供的代码中,你没有指定一个UIButton
types? 用自定义图像创build一个button
// Create image self.fNewNoteIcon = [UIImage imageNamed:@"buttomImage.png"]; // Create rect for button. 0, 0 and size it from image CGRect newNoteButtonRect = CGRectMake:(0, 0, _fNewNoteIcon.size.width, _fNewNoteIcon.size.height); // Alloc and init UIButton with type // Pass in image. Add to subview of view. UIButton *newNoteButton = [UIButton buttonWithType: UIButtonTypeCustom]; [newNoteButton setImage: _fNewNoteIcon forState: UIControlStateNormal]; [self.view addSubview: newNoteButton];
我把所有这一切都input到SO中,而不需要编译这样的检查,但是应该为你提供一个UIButton,所需的图像大小正确。
所以看起来如果你的PNG没有Alpha通道,那么你会遇到尺寸问题。 我在Photoshop中打开了PNG并添加了一个Alpha通道。 现在图像在iPad中正确大小!