在目标 C 中,可以将背景图像设置为拉伸的 png,如下所示:
button = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
[button setTitle: @"Tap me" forState: UIControlStateNormal];
[button setBackgroundImage:[[UIImage imageNamed: @"greenButton.png"]
stretchableImageWithLeftCapWidth:8.0f
topCapHeight:0.0f]
forState:UIControlStateNormal];
尝试将其转换为 Ruby,但我不断收到异常。问题在于 UIImage 实例上调用的两个方法:stretchableImageWithLeftCapWidth和topCapHeight。
我尝试了以下方法无济于事:
greenImage = UIImage.imageNamed("greenButton.png")
greenImage.stretchableImageWithLeftCapWidth = 8.0
greenImage.topCapHeight = 0.0
@timerButton.setBackgroundImage(greenImage, forState: UIControlStateNormal)
任何人都可以建议吗?