UIView无法容纳屏幕顶部显示的整个屏幕白条

时间:2018-08-28 02:31:25

标签: ios swift

我目前有一个UIView,它是UIScrollView的子视图,我希望UIView覆盖UIScrollView顶部的整个屏幕,但是当我加载该应用程序,顶部顶部有一个白色的栏,像这样 White Bar at top of screen

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

上进行测试

这是滚动视图的代码

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()
    }
}

1 个答案:

答案 0 :(得分:0)

在文件info.list中,添加行:View controller-based status bar appearance并设置为NO

 Next in appdelegate:

 UIApplication.shared.statusBarStyle = .lightContent


 i hope work for you!