简体   繁体   中英

Getting View Size Not Getting Resized Size

In the view controller class I'm trying to make buttons programmatically in a 10x10 grid. I have constraints and the view is resizing properly, but the size I'm getting back and seeing from the print statement is the original size from the story board and not the resized size. How do I get the new size?

func buttonGridder() {
    for x in 0..<10 {
        for y in 0..<10{
            let sizer = ButtonGrid.frame.width
            let buttonSize:CGFloat = ButtonGrid.frame.width / CGFloat(10)
            print("\(x), \(y), \(buttonSize), \(sizer)")
            let letterButton = WordButton(column: x, row: y, buttonSize: buttonSize, buttonMargin: 0)
            self.ButtonGrid.addSubview(letterButton)
        }
    }
}

Call the Log function in this method viewDidLayoutSubviews . This is the method that is called after views are positioned accordingly to the constraints after viewDidAppear . Note : This method is called multiple times in a single go, so DO NOT alloc or add in this method.

AND if you are adding or changing the view size later on then call setNeedsDisplay to redraw all the Views inside the View controller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM