iOS 自定义UIButton(图片和文字混合)
// UIApplicationDelegate .h文件
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
// UIApplicationDelegate .m文件
#import "AppDelegate.h"
#import "CustomButton.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
CustomButton *customBtn = [[CustomButton alloc] init];
customBtn.frame = CGRectMake(100,150, 150, 60);
[customBtn setTitle:@"十二年" forState:0];
[customBtn setImage:[UIImage imageNamed:@"De.png"] forState:0];
[self.window addSubview:customBtn];
[self.window makeKeyAndVisible];
return YES;
}
@end
// 自定义CustomButton类,继承UIButton
// CustomButton .h文件
#import <UIKit/UIKit.h>
@interface CustomButton : UIButton
@end
// CustomButton .m文件
#import "CustomButton.h"
@implementation CustomButton
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//设置粗体文字,以及文字的大小
self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
// 设置文字居右
self.titleLabel.textAlignment = NSTextAlignmentRight;
// 设置文字的颜色
[self setTitleColor:[UIColor redColor] forState:0];
// 设置背景图片
self.backgroundColor = [UIColor greenColor];
}
return self;
}
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
CGRect titleFrame = CGRectMake(0, 0, contentRect.size.width * 0.6, contentRect.size.height);
return titleFrame;
}
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
return CGRectMake(contentRect.size.width * 0.6, 0, contentRect.size.width * 0.4, contentRect.size.height);
}
@end
iOS 自定义UIButton(图片和文字混合)的更多相关文章
- 自定义带图片和文字的ImageTextButton
今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...
- Android TextView中有图片有文字混合排列
Android TextView中有图片有文字混合排列 1.使用html.fromHtml 2.新建ImageGetter 3.使用<img src>标签 demo: 1.设置文字 ((T ...
- 自定义带图片和文字的Button的排版--陈棚
自定义button,动态加载图片与文字 [footView addSubview:btnAllChoose]; [btnAllChoose setTitle:str forState:UIContro ...
- 改变UIButton 图片和文字的位置
//设置字体和图片之间的间距 _btnLeft.titleEdgeInsets = UIEdgeInsetsMake(0, -_btnLeft.imageView.frame.size.width, ...
- 自定义组件---图片和文字实现ImageButton效果
1.效果图 2.自定义代码: <span style="font-family:Comic Sans MS;font-size:14px;">public class ...
- iOS 自定义UIButton
工作中有一个点击button更新button上文案的需求,用自定义了button可以很简单的实现的这个需求 首先写个自定义的button CustomButton.h #import <UIKi ...
- h5 安卓/IOS长按图片、文字禁止选中或弹出系统菜单 的解决方法
最近在做IM的语音功能,发现当长按录音的时候手机会弹出来系统菜单, IOS下bug形式:1)长按的标签设置为css background的形式:不会弹出菜单: 2)但是当设置为img时,系统默认识别为 ...
- UIButton图片与文字位置调整
1:左图右文 默认效果就行 2:左文右图 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn addTarget:se ...
- ios自定义UIButton内部空间Rect
随机推荐
- [ZZ] Cache
http://blog.sina.com.cn/s/blog_6472c4cc0102duzr.html 处理器微架构访问Cache的方法与访问主存储器有类似之处.主存储器使用地址编码方式,微架构可以 ...
- GTX780
- WampServer 在 httpd.conf 中配置多站点 (IP 配置法:不用每次修改 hosts 文件 + 域名配置法 )
因为要用 ThinkPHP 的当前最新版本 3.2.2,对应要求 PHP 的版本要高于 5.3.0,所以安装了 WampServer 2.2 ( Apache 2.2.21,PHP 5.3.10,My ...
- ThinkPHP 学习笔记 ( 三 ) 数据库操作之数据表模型和基础模型 ( Model )
//TP 恶补ing... 一.定义数据表模型 1.模型映射 要测试数据库是否正常连接,最直接的办法就是在当前控制器中实例化数据表,然后使用 dump 函数输出,查看数据库的链接状态.代码: publ ...
- 郎科U208(主控 PS2251-50 HYNIX H27UCG8T2MYR)量产还原
6年前的一个U盘 记得还是参加某会议送的,当时做了量产 多做了一个光盘区,现在用不着了 想还原成普通U盘 忘了方法. 可见笔记的重要性 Chipgenius看了主控 PS2251-50 芯片是海力士 ...
- NEC学习 ---- 布局 -两列, 左侧定宽,右侧自适应
CSS代码:以下两处代码是NEC中CSS初始化样式和功能性样式.今后的NEC研究中,默认这两处是引用的. /* 这是CSS reset 代码 --- 初始化样式 */ /* reset */ html ...
- PHP文件操作 之往一个文件写入数据
//打开一个文件 $f = fopen($filename,'wb'); $filename:打开一个文件,不存在则自动创建,如果不能创建,说明指定的文件目录有错误 wb:写入的方式 ---- 覆盖原 ...
- Distinctive Image Features from Scale-Invariant
http://nichol.as/papers/Lowe/Distinctive Image Features from Scale-Invariant.pdf Abstract This paper ...
- Image Formats
http://www.html5rocks.com/en/tutorials/speed/img-compression/ https://developers.google.com/speed/we ...
- Machine Learning in Action -- 回归
机器学习问题分为分类和回归问题 回归问题,就是预测连续型数值,而不像分类问题,是预测离散的类别 至于这类问题为何称为回归regression,应该就是约定俗成,你也解释不通 比如为何logistic ...