制作UIButton。由于某种原因,它周围有一个白色的间隙(灰色区域是按钮所在的UIView):
代码:
UIView *photoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, (THUMBNAIL_SIZE) + (PHOTO_VIEWER_OFFSET_COLUM_1 * 2))];
photoView.backgroundColor = [UIColor lightGrayColor];
UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, photoView.frame.size.height)];
myScrollView.backgroundColor = [UIColor lightGrayColor];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(0, 0, 50, 50);
myButton.titleLabel.font = [UIFont fontWithName:labelFont size:16];
[myButton setTitle:@"X" forState:UIControlStateNormal];
[myButton setBackgroundImage:[UIImage imageNamed:@"add-report.png"] forState:UIControlStateNormal];
myButton.center = CGPointMake(((photoView.frame.size.width - myScrollView.frame.size.width) / 2) + myScrollView.frame.size.width, photoView.frame.size.height / 2);
[photoView addSubview:myButton];
[self.view addSubview:photoView];
我不想要那里的白色缓冲空间,但我无法弄清楚如何摆脱它。
任何想法?
编辑:如果我尝试更改背景颜色:
myButton.backgroundColor = [UIColor orangeColor];
我得到了这个效果:
答案 0 :(得分:0)
可能是默认情况下白色背景的文字标签?
尝试将每种颜色设置为[UIColor clearColor]
,例如button.background
和button.titleLabel.background
。
还尝试修改图像视图。也许它没有按预期自动扩展:
button.imageView.contentMode = UIViewContentModeScaleToFill;