How to achieve UIButton / UILabel 'padding' in iPhone app

前端 未结 10 2064
挽巷
挽巷 2021-01-31 13:40

I\'ve got various views in my iPhone application that require padding e.g a custom UIButton with text aligned left, and a UILabel with a background color.

This may be a

10条回答
  •  情歌与酒
    2021-01-31 14:14

    CGRectInset is your friend. You can set negative 'insets' to create padding:

    [self sizeToFit];
    CGRect rect = self.frame;
    rect = CGRectInset( rect, -6.f, -5.f); // h inset, v inset
    self.frame = rect;
    

提交回复
热议问题