Is it possible to adjust x,y position for titleLabel of UIButton?

前端 未结 5 669
野趣味
野趣味 2021-01-29 18:25

Is it possible to adjust the x,y position for the titleLabel of a UIButton?

Here is my code:

    UIButton *btn = [UIButton but         


        
5条回答
  •  时光说笑
    2021-01-29 18:38

    Derive from UIButton and implement the following method:

    - (CGRect)titleRectForContentRect:(CGRect)contentRect;
    

    Edit:

    @interface PositionTitleButton : UIButton
    @property (nonatomic) CGPoint titleOrigin;
    @end
    
    @implementation PositionTextButton
    - (CGRect)titleRectForContentRect:(CGRect)contentRect {
      contentRect.origin = titleOrigin;
      return contentRect;
    }
    @end
    

提交回复
热议问题