Adding padding to an UIView

后端 未结 7 1341
长情又很酷
长情又很酷 2020-12-23 12:55

I\'m looking for a way to add a padding property to an UIView. Ideally, I would like to avoid subclassing and putting it in a category. The usage would be somet

7条回答
  •  借酒劲吻你
    2020-12-23 13:53

    What you really have to do is create a view and add a subview to it. Make one view the background and give it the frame you want. Then make the second subview the frame you want with the edge insets.

    UIView backgroundView = new UIView(CGRect.FromLTRB(0, 0, 100, 100))
    {
        BackgroundColor = backgroundGray,
    };
    
    //Will have a right edge inset of 10
    UIView edgyView = new UIView(CGRect.FromLTRB(0, 0, 90, 100))
    {
        BackgroundColor = backgroundGray,
    }
    
    backgroundView.AddSubview(edgyView);
    

提交回复
热议问题