ios - UIView 不适合整个屏幕 屏幕顶部显示白色条

标签 ios swift

我目前有一个 UIView,它是 UIScrollView 的 subview ,我希望 UIView 覆盖整个屏幕的顶部UIScrollView,但是当我加载应用程序时,顶部有一个白条,如下所示 White Bar at top of screen

我不使用storyboard,而是以编程方式创建所有元素。我目前正在 iPhone X 上进行测试

这是 ScrollView 的代码

import Foundation
import UIKit
import PureLayout

class profileView: UIScrollView {

    var shouldSetupConstraints = true
    var profileImageContainer = UIView()
    var profileImage = UIImageView(image: UIImage(named: "logo"))
    var profileInfo = UIView()
    var name = UILabel()

    let screenSize = UIScreen.main.bounds
    let gradient = CAGradientLayer()
    let profilegradient = CAGradientLayer()
    let textFieldAppearance = UITextField.appearance()


    override init(frame: CGRect) {
        super.init(frame: frame)

        gradient.colors = [UIColor(red: (96/255.0), green: (95/255.0), blue: (95/255.0), alpha: 0.65).cgColor , UIColor(red: (35/255.0), green: (39/255.0), blue: (42/255.0), alpha: 1).cgColor]
        gradient.startPoint = CGPoint(x: 0, y: 0)
        gradient.endPoint = CGPoint(x: 0, y: 1)
        gradient.cornerRadius = 4

        profilegradient.colors = [UIColor(red: (96/255.0), green: (95/255.0), blue: (95/255.0), alpha: 0.65).cgColor , UIColor(red: (35/255.0), green: (39/255.0), blue: (42/255.0), alpha: 1).cgColor]
        profilegradient.startPoint = CGPoint(x: 0, y: 0)
        profilegradient.endPoint = CGPoint(x: 0, y: 1)

        profileImageContainer.frame = CGRect(x: 0, y:0, width: screenSize.width, height: screenSize.height)
        profilegradient.frame = profileImageContainer.bounds
        profileImageContainer.layer.insertSublayer(profilegradient, at:0)

        self.addSubview(profileImageContainer)

        profileImage.center = CGPoint(x: screenSize.width/2, y:screenSize.height/2)

        profileImageContainer.addSubview(profileImage)


        profileInfo.frame = CGRect(x: 0, y: screenSize.height/1.3, width: screenSize.width, height: 150)
        gradient.frame = profileInfo.bounds
        profileInfo.layer.insertSublayer(gradient, at:0)

        self.addSubview(profileInfo)

        name.frame = CGRect(x: screenSize.width/20, y: 0, width: screenSize.width, height: 50)
        name.font = UIFont(name: "HelveticaNeue-medium", size: 32)
        name.textColor = .white

        profileInfo.addSubview(name)

        textFieldAppearance.keyboardAppearance = .light
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func updateConstraints() {
        if(shouldSetupConstraints) {
            // AutoLayout constraints
            shouldSetupConstraints = false
        }
        super.updateConstraints()
    }
}

最佳答案

在文件 info.list 中,添加行:查看基于 Controller 的状态栏外观 并设置为 NO

 Next in appdelegate:

 UIApplication.shared.statusBarStyle = .lightContent


 i hope work for you! 

关于ios - UIView 不适合整个屏幕 屏幕顶部显示白色条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52049258/

相关文章:

swift - 从菜单栏项运行 shell 命令

ios - 在 iOS 中捕获崩溃和异常

ios - 在 Fabric 中上传 ios build .dSYM 文件需要很长时间

iphone - 应用程序设计提醒(UILocalNotifications?)

长按时出现 iOS 7 UITableViewCell 按钮

swift - 如何在 swift 中克隆像 Java 这样的对象

swift - 以自定义大小阅读图库视频

swift - 将可见性绑定(bind)到 arrayController 选择

ios - 如何从 url 链接设置左侧导航栏按钮图像?

ios - 在 iOS 上禁用 'Don' t Reopen' 或 'Reopen' 对话框