LoginSignup
0
0

More than 5 years have passed since last update.

重绘button

Posted at

使用此方法可以改变系统button中image,title的位置,大小。

1.首先需要创建一个继承于UIbutton的类,并且设置一个属性,用作比例

@interface ToolsBtn : UIButton

@property (nonatomic,assign) CGFloat raido;

@end

2.在实现中实现button的两个方法便可

//返回的是按钮内部图片的 frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect{

    CGRect imageRect = CGRectMake((1- _raido) * CGRectGetWidth(contentRect) / 2.0, 0, CGRectGetWidth(contentRect) * _raido, CGRectGetWidth(contentRect) * _raido);
    return imageRect;


}
//返回的是按钮内部 titleLabel的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect{

    CGRect titleRect = CGRectMake(0, CGRectGetWidth(contentRect) * _raido, CGRectGetWidth(contentRect) , CGRectGetWidth(contentRect)*(1-_raido));
    return titleRect;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0