在标签栏“更多”标签SWIFT中调整webView的大小

萨查

嗨,我是堆栈溢出的新手,大约一周前我遇到了一个问题:

我的IOS应用程序基于此,UIWebView它们位于选项卡栏的不同选项卡中,共有9个选项卡,这些选项卡显示完全正常,但随后,“更多”部分中的选项卡似乎全部被窃听了,并且有一个空白在webView的顶部和底部,我想知道如何根据视图可以占据的空间来调整它的大小,或者如何简单地取出该黑色空间...

g +黑线屏幕截图

谢谢萨莎

更新:修复了顶部,但底部的一些像素仍然不是webView白色底部的一部分

瓦西里·博德纳丘克(Vasily Bodnarchuk)

您需要设置webView的scrollView的contentInset:

webView.scrollView.contentInset = UIEdgeInsetsZero

聋子

在此处输入图片说明

webView.scrollView.contentInset = UIEdgeInsetsZero

在此处输入图片说明

完整示例:

带有ViewController的示例,但该想法适用于tabBarController(或带有tabBar的viewController)

WebViewController.swift

import UIKit

class WebViewController: UIViewController, UIWebViewDelegate {

@IBOutlet var webView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


    let startUrl = "http://apple.com"
    if let url = NSURL(string: startUrl) {
        webView.loadRequest(NSURLRequest(URL: url))
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews();

    webView.scrollView.contentInset = UIEdgeInsetsZero
} 
}

主板

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="fNb-w0-GoK">
<dependencies>
    <deployment identifier="iOS"/>
    <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
    <!--View Controller-->
    <scene sceneID="tne-QT-ifu">
        <objects>
            <viewController id="BYZ-38-t0r" sceneMemberID="viewController">
                <layoutGuides>
                    <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
                    <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
                </layoutGuides>
                <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
                    <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    <subviews>
                        <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qYE-Qt-Pdb">
                            <rect key="frame" x="277" y="285" width="46" height="30"/>
                            <state key="normal" title="Button"/>
                            <connections>
                                <segue destination="WGg-GA-JYj" kind="show" identifier="toWebViewController" id="X7W-oO-znq"/>
                            </connections>
                        </button>
                    </subviews>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                    <constraints>
                        <constraint firstItem="qYE-Qt-Pdb" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Yp4-rg-uRU"/>
                        <constraint firstItem="qYE-Qt-Pdb" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="hCZ-Me-NTn"/>
                    </constraints>
                </view>
                <navigationItem key="navigationItem" id="ypr-4x-iVU"/>
            </viewController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
        </objects>
        <point key="canvasLocation" x="1099" y="559"/>
    </scene>
    <!--Web View Controller-->
    <scene sceneID="OnG-Ir-ldX">
        <objects>
            <viewController id="WGg-GA-JYj" customClass="WebViewController" customModule="stackoverflow_39097959" customModuleProvider="target" sceneMemberID="viewController">
                <layoutGuides>
                    <viewControllerLayoutGuide type="top" id="aes-Hs-ALg"/>
                    <viewControllerLayoutGuide type="bottom" id="k9x-oU-rHI"/>
                </layoutGuides>
                <view key="view" contentMode="scaleToFill" id="cnA-Wg-EC0">
                    <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    <subviews>
                        <webView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1wq-mG-bgW">
                            <rect key="frame" x="0.0" y="64" width="600" height="536"/>
                            <color key="backgroundColor" red="0.36078431370000003" green="0.38823529410000002" blue="0.4039215686" alpha="1" colorSpace="deviceRGB"/>
                        </webView>
                    </subviews>
                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                    <constraints>
                        <constraint firstItem="1wq-mG-bgW" firstAttribute="leading" secondItem="cnA-Wg-EC0" secondAttribute="leading" id="6ba-OZ-vfB"/>
                        <constraint firstItem="1wq-mG-bgW" firstAttribute="top" secondItem="aes-Hs-ALg" secondAttribute="bottom" id="Krw-Xl-SDX"/>
                        <constraint firstAttribute="trailing" secondItem="1wq-mG-bgW" secondAttribute="trailing" id="qk7-A7-tXd"/>
                        <constraint firstItem="1wq-mG-bgW" firstAttribute="bottom" secondItem="k9x-oU-rHI" secondAttribute="top" id="scz-71-oN5"/>
                    </constraints>
                </view>
                <navigationItem key="navigationItem" id="1tS-GL-oIH"/>
                <connections>
                    <outlet property="webView" destination="1wq-mG-bgW" id="u7n-Tl-NII"/>
                </connections>
            </viewController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="0Rf-a9-fCM" userLabel="First Responder" sceneMemberID="firstResponder"/>
        </objects>
        <point key="canvasLocation" x="1818" y="559"/>
    </scene>
    <!--Navigation Controller-->
    <scene sceneID="0Hz-no-KQO">
        <objects>
            <navigationController automaticallyAdjustsScrollViewInsets="NO" id="fNb-w0-GoK" sceneMemberID="viewController">
                <toolbarItems/>
                <navigationBar key="navigationBar" contentMode="scaleToFill" id="I39-SK-Dmu">
                    <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
                    <autoresizingMask key="autoresizingMask"/>
                </navigationBar>
                <nil name="viewControllers"/>
                <connections>
                    <segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="Zkp-F4-EwR"/>
                </connections>
            </navigationController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="ptJ-Hj-WO2" userLabel="First Responder" sceneMemberID="firstResponder"/>
        </objects>
        <point key="canvasLocation" x="378" y="559"/>
    </scene>
</scenes>
</document>

在您的项目中:

另外,我修复了您的情节提要viewController。您设置了错误的约束。

在此处输入图片说明

块引用

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Swift中调整文本大小以适合标签

来自分类Dev

在html中调整标签的大小

来自分类Dev

在Flutter标签栏中,所选标签栏的大小和标签栏的大小无法对齐。如何对齐?

来自分类Dev

在Scrollview中动态调整标签的大小?

来自分类Dev

TableCell中的标签未调整大小

来自分类Dev

iOS 7.1问题-标签栏调整大小不起作用

来自分类Dev

Swift中搜索栏中的标签

来自分类Dev

使用Swift在iOS中根据标签数据调整标签

来自分类Dev

SwiftUI:在更多标签中更改导航栏标题吗?

来自分类常见问题

在iOS Swift应用中隐藏标签栏

来自分类Dev

在Swift中更改标签栏字体

来自分类Dev

自动调整div标签的大小

来自分类Dev

在Rebol3 Saphir中自动调整标签大小

来自分类Dev

在Windows窗体应用程序中调整标签大小

来自分类Dev

在Tkinter中调整笔记本标签的大小

来自分类Dev

出于版权目的,在html标签中调整图像大小

来自分类Dev

在Rebol3 Saphir中自动调整标签大小

来自分类Dev

如何使 iOS 渲染器中的标签环绕并调整大小?

来自分类Dev

在状态栏中隐藏标签大小Sublime Text

来自分类Dev

动作栏中的标签

来自分类Dev

调整窗口大小时,如何更改导航栏上li标签的值/内容?

来自分类Dev

调整窗口大小时,如何更改导航栏上li标签的值/内容?

来自分类Dev

调整窗口大小时删除<br />标签

来自分类Dev

iText:按钮调整大小会影响标签

来自分类Dev

如果溢出,请调整JavaFX标签的大小

来自分类Dev

如何按比例调整标签大小

来自分类Dev

调整窗口大小时删除<br />标签

来自分类Dev

如何为不同的标签调整 Qtabwidget 的大小?

来自分类Dev

调整大小时扭曲的标签文本

Related 相关文章

热门标签

归档