iOS调整按纽图片文字title位置的代码
2018-07-20 来源:open-open
自定义一个button,要调整 button中的image(注意,不是backgroundImage) 和 title 文字的位置,只需要重写 Button类独对应的两个方法即可:
首先,我们来创建一个 SuperButton继承自 UIButton
//
// SuperButton.h
// SuperButton #import <UIKit/UIKit.h>
@interface SuperButton : UIButton
@end
实现文件
//
// SuperButton.m
// SuperButton
//
//
#import "SuperButton.h"
#import "UtilsFunctions.h"
@interface SuperButton ()
{
CGRect boundingRect;
}
@end
@implementation SuperButton
//自定义的初始化方法
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self setTitle:@"项目介绍" forState:UIControlStateNormal];
[self.titleLabel setFont:[UIFont boldSystemFontOfSize:font]];
[self setBackgroundImage:[UIImage imageNamed:@"cpxq_shang@3x.png"] forState:UIControlStateNormal];
[self setImage:[UIImage imageNamed:@"cpxq_jiantou2@3x.png"] forState:UIControlStateNormal];
boundingRect=[self.titleLabel.text boundingRectWithSize:CGSizeMake(320,font) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil];
}
return self;
} 标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:一个自定义php错误函数
下一篇:curl post方式访问网页
最新资讯
热门推荐