감사하겠습니다 내가이해야 할 일의 빠른 설명이나 새로운 튜토리얼을 줄 수 있다면 감사 어떤 도움 어떻게 UIView
가 정확하게 작동하는지. nibs/storyboard가 새로운 iOS 개발자를 혼란스럽게하는 데 정말 좋습니다. 본질적
하는
UIViewController
사용하면
[self setView:someUIView]
을 사용하여
viewDidLoad
또는
loadView
있어서 설정 한 볼 수있다. 당신은
UIView
을 viewcontroller의 "Main"뷰의 하위 뷰로 추가하여 더 많은 내용을 화면에 추가합니다. 예를 들어
-(void)loadView {
// Create a view for you view controller
UIView *mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self setView:mainView];
// Now we have a view taking up the whole screen and we can add stuff to it
// Let's try a button, a UIButton is a subview of UIView
UIButton *newButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect];
// We need to set a frame for any view we add so that we specify where it should
// be located and how big it should be!
[newButton setFrame:CGRectMake(x,y,width,height)];
// Now let's add it to our view controller's view
[self.view addSubview:newButton];
// You can do the same with any UIView subclasses you make!
MyView *myView = [[MyView alloc] init];
[myView setFrame:CGRectMake(x,y,width,height)];
[self.view addSubview:myView];
}
지금 여기에 우리는 우리의 ViewController who'se보기 그냥 다시 2 파단이있는 일반의 UIView입니다있다; newButton 및 myView MyView 클래스를 만들었으므로 서브 뷰도 포함되어있을 수 있습니다. 그래서이 예에서 우리가 지금이 버튼을 포함 볼 who'se보기 컨트롤러 것
// Here is the init method for our UIView subclass
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Let's add a button to our view
UIButton *newButton2 = [[UIButton buttonWithType:UIButtonTypeRoundedRect];
// Of course, the frame is in reference to this view
[newButton2 setFrame:CGRectMake(x,y,width,height)];
// We add just using self NOT self.view because here, we are the view!
[self addSubview:newButton2];
}
return self;
}
:의는 UIView 하위 모습 수 있는지 살펴 보자! 그러나보기 구조는 나무입니다.
mainView
/ \
newButton myView
\
newButton2
다른 질문이 있으면 알려주세요.
매트
출처
2012-02-14 18:47:38
MGA
나는 잘 모르겠다. Xcode의 버전은 귀하의 질문과 정확히 어떤 관계가 있습니까? 파일> 새로 만들기> 새 파일을 선택하여 UIView 하위 클래스를 만들 수 있습니다. – MGA
그 작업을 수행 할 수 있었지만 처음보기의 단추에 어떻게 연결합니까? – user1208173
어이 거기에 user1208173. 내 대답이 도움이 되었기를 바랍니다. 다른 질문이 있으면 알려주세요. 내 대답이 귀하의 문제를 해결하는 데 도움이된다면, 정답으로 선택하면 감사하겠습니다. 감사합니다! – MGA