2013-12-11 7 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에는 단추 및 레이블과 같은 다른보기가 있습니다. 알려 주시기 바랍니다 –

관련 문제