我正在開發ViewController
,其中一些UI元素爲SubViews
,但是當我在不同設備上運行應用時,這些元素存在問題。我正在通過代碼做所有事情。我應該使用AutoLayout
?我應該如何使用這個元素的autolayout?如何在不同屏幕的正確位置放置子視圖
我有以下項目:
titleLbl = [[WPCustomLabel alloc] initWithFrame:CGRectMake(30, self.view.frame.size.height/2, 260, 25)];
[titleLbl setFont:[UIFont systemFontOfSize:18]];
[self.view addSubview:titleLbl];
NSLog(@"%f", self.view.bounds.size.height/2);
textLbl = [[WPCustomLabel alloc] initWithFrame:CGRectMake(40, self.view.frame.size.width/2 + 10, 250, 230)];
[textLbl setTextAlignment:NSTextAlignmentJustified];
[self.view addSubview:textLbl];
omitBtn = [[WPCustomButton alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-108 , self.view.bounds.size.width/2, 44)];
[omitBtn setTitle:@"Omitir" forState:UIControlStateNormal];
[omitBtn addTarget:self action:@selector(omitInfo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:omitBtn];
nextBtn = [[WPCustomButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height-108, self.view.frame.size.width/2, 44)];
[nextBtn setTitle:@"Siguiente" forState:UIControlStateNormal];
[nextBtn addTarget:self action:@selector(omitInfo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextBtn];
您是否使用AutoLaoyouts嘗試過故事板? –
我不使用故事板.. – croigsalvador
根據需要重寫'viewWillLayoutSubviews'方法並基於'self.view'的幀更新幀。 – rmaddy