回答
您需要将控制器的视图设置为蓝色背景。然后,添加具有白色背景与期望的角半径的新的子视图:
[self.view setBackgroundColor:[UIColor blueColor]];
UIView *roundedBox = [[UIView alloc] initWithFrame:CGRectMake(20, 60, 280, 280)];
[roundedBox setBackgroundColor:[UIColor whiteColor]];
[roundedBox.layer setCornerRadius:10];
[self.view addSubview:roundedBox];
你需要确保你导入QuartzCore,由于需要直接处理层,这是怎么了设置角落半径:
#import <QuartzCore/QuartzCore.h>
view.backgroundColor = [UIColor whiteColor];
view.layer.cornerRadius = 10;
view.layer.maskToBounds = YES;
谢谢。我相信这会将整个背景颜色设置为白色。有没有一个控制器可以完成这一点。谢谢 –
更困难,但功能更强大的方式来做到这一点是bezierPathWithRoundedRect:cornerRadius。你将不得不创建一个新的UIView。我个人的子类的UIView,你已经创建后,添加类似:
UIBezierPath *roundedCornerRectangle = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10]; // create bezier path
UIRectFill(self.bounds); // initialize rectangle onto view, will appear with default settings which is a black rectangle
[[UIColor whiteColor] setFill]; // set color to white
[roundedCornerRectangle fill]; // fill rectangle with color
[self drawShape];
这可以通过容器视图来实现吗? –
UIBezierPath会保存其他视图,如按钮和标签。请让我知道 –
- 1. 如何在web视图中移除白色背景?
- 2. 的iOS:如何使用白色背景
- 3. 如何在OpenCV中创建背景黑色和前景白色?
- 4. Bootstrap将白色身体放置在背景之上图片
- 5. UILabel在子视图中有一个白色背景
- 6. UINavigationController视图的背景变成白色
- 7. 如何从视图中释放背景
- 8. 如何更改背景视图颜色偏爱在ios swift
- 9. 在白色背景上显示白色图像为灰色:Android
- 10. 在UIImageView中删除白色背景
- 11. 背景在Fancybox iframe中闪烁白色
- 12. 白色背景()
- 13. 从图像中删除白色背景
- 14. 从图像中删除白色背景
- 15. 图片GD - 白色背景
- 16. 将模态视图放在视图上并将背景变为灰色
- 17. 如何将QImage与灰色背景放在QIcon中?
- 18. 如何将带有透明背景的白色徽标图像放在黑色标题中?
- 19. 如何将PNG透明背景转换为JPG白色背景?
- 20. iOS。用GPUImage在相机视图上播放带有绿色背景的视频
- 21. swift中的白色背景图像上的白色文字
- 22. iOS褪色白色背景上的强烈白色文字?
- 23. 如何在onRestoreInstanceState()中设置视图的背景颜色
- 24. 如何在swift中更改子视图的背景颜色?
- 25. 如何在MVC视图中更改动态行背景颜色?
- 26. 不透明的白色背景与rgba在白色背景显示灰色?
- 27. 在cocos2d/IOS中获取背景颜色
- 28. 在图像视图中模糊图像在背景iOS
- 29. PHPExcel白色背景
- 30. 在tds中放置背景颜色Javascript
谢谢hukir。我很想添加蓝色的圆形框。但按钮和标签消失。你能帮助我如何将它们放在子视图中 –
我明白了。我需要做的是添加语句[self.view addSubview:label];在由hukir给出的代码之后。谢谢Hukir –