axiixc의 의견을 계속 이어 가며, 여기에 웹보기 하단에 버튼을 배치하는 데 사용할 수있는 코드가 있습니다. 레이아웃 서브 뷰에 위치 지정 코드를두면 회전을 올바르게 처리 할 수 있습니다.
- (void)webViewDidFinishLoad:(UIWebView *)webview{
if (!_button){
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"Move All Blue Cards to Known" forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"signin-button-blue-color"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
[_webview.scrollView addSubview:button];
_button = button;
}
[self setNeedsLayout];
[self layoutIfNeeded];
}
- (void)layoutSubviews{
[super layoutSubviews];
float y = 0;
CGRect originalRect = _webview.frame;
_webview.frame = CGRectMake(0, 0, originalRect.size.width, 1); // Trick the webview into giving the right size for content
CGSize contentSize = _webview.scrollView.contentSize;
_webview.frame = originalRect;
if (contentSize.height < _webview.frame.size.height){ // This keeps the button at the bottom of the webview, or at the bottom of the content, as needed.
y = _webview.frame.size.height - 64; // 44 tall + 20 offset from the bottom
} else {
y = contentSize.height + 20;
}
_button.frame = CGRectMake(20, y, self.frame.size.width-40, 44); // 40/2 = 20 px on each side
contentSize.height = CGRectGetMaxY(_button.frame)+20;
_webview.scrollView.contentSize = contentSize;
}
인터페이스 빌더의 웹 vew에 단추를 추가하거나 웹보기의 프레임 크기를 줄이고보기에 단추를 추가 할 수 있습니다. – Sandeep