我想将图像设置为按钮上的背景。所以我创建了一个图像:
然后我想把它实现为可伸缩的:
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)
应该是不可靠的角落,对吗?
答案 0 :(得分:2)
根据文档,插图内的部分(未通过上限设置锁定的部分)是平铺。所以你应该有一个小的1像素区域来平铺。例如。将插图设为UIEdgeIndetsMake(20,8,19,7)
这会产生:
答案 1 :(得分:1)
[button setBackgroundImage:[[UIImage imageNamed:@"image.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(20.f, 62.f, 20.f, 62.f)] forState:UIControlStateNormal];