2013-12-11 100 views

回答

1

您需要将控制器的视图设置为蓝色背景。然后,添加具有白色背景与期望的角半径的新的子视图:

[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> 
+0

谢谢hukir。我很想添加蓝色的圆形框。但按钮和标签消失。你能帮助我如何将它们放在子视图中 –

+0

我明白了。我需要做的是添加语句[self.view addSubview:label];在由hukir给出的代码之后。谢谢Hukir –

0
view.backgroundColor = [UIColor whiteColor]; 
view.layer.cornerRadius = 10; 
view.layer.maskToBounds = YES; 
+0

谢谢。我相信这会将整个背景颜色设置为白色。有没有一个控制器可以完成这一点。谢谢 –

0

更困难,但功能更强大的方式来做到这一点是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]; 
+0

这可以通过容器视图来实现吗? –

+0

UIBezierPath会保存其他视图,如按钮和标签。请让我知道 –

相关问题