首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >iOS_UIButton将image分别显示在上下左右

iOS_UIButton将image分别显示在上下左右

作者头像
mikimo
发布2022-07-20 14:34:41
发布2022-07-20 14:34:41
6720
举报
文章被收录于专栏:iOS开发~iOS开发~

MOImageButton

利用 Mansory / SnapKit 调整按钮的图片位置,分别显示在上下左右:

How to use

一、OC:

1、add the MOImageButton.h and MOImageButton.m files into your project

2、then import "MOImageButton.h" when need use file

3、code such as:

代码语言:javascript
复制
// set image type
MOImageButton *btn = [MOImageButton buttonWithType:UIButtonTypeCustom imageType:type]; 
btn.backgroundColor = [UIColor grayColor];
[btn setTitle:@"自适应宽度" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setImage:[UIImage imageNamed:@"icon_delete"] forState:UIControlStateNormal];
[self addSubview:btn];
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
  make.top.mas_equalTo(220);
  make.left.mas_equalTo(20);
}];
[btn moLayout]; // use after add to superView

二、Swift:

1、add MOButton.swift file into your project

2、code such as:

代码语言:javascript
复制
let btn: MOButton = MOButton(type: .custom)
btn.moType = type // set image type
btn.backgroundColor = .gray
btn.setTitle("自适应宽度", for: .normal)
btn.setTitleColor(.black, for: .normal)
btn.setImage(UIImage(named: "icon_delete"), for: .normal)
self.addSubview(btn)
btn.snp.makeConstraints { (make) in
  make.top.equalTo(220)
  make.centerX.equalToSuperview()
}
btn.moLayout() // use after add to superView
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-12-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • MOImageButton
  • How to use
    • 一、OC:
    • 二、Swift:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档