0

I already have labels displaying on my externals screen but I want to add a blue rectangle of Width: 500px and Height: 50px.

What would be the code to add this?

This is the code I use for my Label.

var secondWindow: UIWindow!
var secondScreenView: UIView!

@objc func setupScreen(){
    if UIScreen.screens.count > 1{
        let secondScreen = UIScreen.screens[1]

        secondWindow = UIWindow(frame: secondScreen.bounds)

        let viewController = UIViewController()
        secondWindow!.rootViewController = viewController

        secondWindow!.screen = secondScreen

        secondScreenView = UIView(frame: secondWindow!.frame)

        secondWindow!.addSubview(secondScreenView)

        secondWindow!.isHidden = false

        // CUSTOMISE VIEW
        secondScreenView.backgroundColor = UIColor.white

        // BATTING TEAM NAME - EXTERNAL
        battingTeamNameLabel.font = UIFont(name: "Arial-BoldMT", size: 80.0)
        battingTeamNameLabel.textColor = UIColor.blue
        battingTeamNameLabel.frame.origin = CGPoint(x:50, y:10)
rmaddy
  • 314,917
  • 42
  • 532
  • 579
J.Kearney
  • 7
  • 1
  • 7
  • You already know how to add views and labels to your second window. What issue are you having adding one more view with a blue background? – rmaddy Dec 20 '18 at 00:57
  • I’m wanting to put my label text within a Blue rectangle. Sorry if it’s a stupid question – J.Kearney Dec 20 '18 at 01:09
  • Put your label in inside a `UIView` and set the view's background color – Paulw11 Dec 20 '18 at 01:44
  • Thanks Paulw11. What if I want the rectangle to be a different size though? (eg. Bigger than my label. I was thinking if I can create the rectangle separate it would be easier. – J.Kearney Dec 20 '18 at 03:09
  • Yes, the `UIView` is the rectangle. Size it however you want. Add the `UILabel` as a sub-view and set its constraints to position it how you want. – Paulw11 Dec 20 '18 at 03:27
  • So I would be putting a UIView inside a UIView? I already have my main UIView which is White. – J.Kearney Dec 20 '18 at 04:09

0 Answers0