我想将图像设置为按钮的背景。所以我创建了一个图像:
然后我想将它实现为可拉伸的:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 200, 400)];
[button setTitle:@"Test Button" forState:UIControlStateNormal];
UIImage *buttonImage = [_model.background resizableImageWithCapInsets:UIEdgeInsetsMake(6, 8, 6, 7)]; //this is screen 1
//UIImage *buttonImage = _model.background; //this is screen 2
[button addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[self addSubview:button];
我想像在屏幕 2 中一样进行背景拉伸,但角落会像屏幕 1 一样锐利。_model.background 是 UIImage 包含来自这篇文章顶部的原始按钮背景。
我用对了吗?我遵循文档,所以UIEdgeInsetsMake(top,left,bottom,right)
应该是不可触及的角落,对吧?