【发布时间】:2011-07-02 10:42:19
【问题描述】:
看:
//UIImageView* stretchTest = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
//[self addSubview:stretchTest];
UIButton *stretchTest = [UIButton buttonWithType:UIButtonTypeCustom];
[stretchTest setFrame:CGRectMake(0, 0, 400, 100)];
[stretchTest setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[self addSubview:stretchTest];
stretchTest.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
stretchTest.contentMode = UIViewContentModeScaleToFill;
CGRect frame = stretchTest.frame;
frame.size.height = 300;
stretchTest.frame = frame;
使用 UIImageView(上面已注释掉),图像会适当拉伸 - 圆角保持正确的半径,因为只有图像的中心像素会被拉伸。
使用 UIButton,图像被错误地拉伸。圆角半径没有保持,变得丑陋。
UIImageView 和 UIButton 都是 UIView 的子类。为什么按钮的调整大小与 imageView 不同?
【问题讨论】:
标签: ios uiview uiimageview uibutton