我目前有一个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()
}
}
答案 0 :(得分:0)
在文件info.list中,添加行:View controller-based status bar appearance
并设置为NO
Next in appdelegate:
UIApplication.shared.statusBarStyle = .lightContent
i hope work for you!