iOS frame change one property (eg width)

前端 未结 9 1037
日久生厌
日久生厌 2020-12-14 00:20

This question was originally asked for the objective-c programming language. At the time of writing, swift didn\'t even exist yet.

Question

Is it po

9条回答
  •  一向
    一向 (楼主)
    2020-12-14 01:00

    In Swift you could extend the UIView class for the app, such that you could, for example, move the table header view up by 10 points like this:

        tableView.tableHeaderView!.frameAdj(0, -20, 0, 0)
    

    (of course if you're using AutoLayout, that might not actually do anything... :) )

    By extending UIView (affecting every UIView and subclass of it in your app)

    extension UIView {
        func frameAdj(x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) {
                self.frame = CGRectMake(
                    self.frame.origin.x + x,
                    self.frame.origin.y + y,
                    self.frame.size.width  + width,
                    self.frame.size.height + height)
        }
    }
    

提交回复
热议问题