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
随机推荐
- ProtocalBuffers学习记录
Google Protocol Buffer 的使用和原理 Google Protocol Buffers 概述 Google Protocol Buffers 入门 Protocol Buffers ...
- 2016.04.28,英语,《Vocabulary Builder》Unit 20
nom, comes from the Latin word for 'name'. nominee is 'named', [ˌnɑːmɪ'niː] n. 被提名的人, 名义人. binomial ...
- [DX11] Introduction
http://www.cnblogs.com/clayman/archive/2011/10/18/2216889.html The Beauty of DirectX 11
- sql in查询排序
1.默认下,使用select xxx where in(xx,xx)查询,返回结果是按主键排序的,如果要按in()中值的排列顺序,可以这样做: select * from talbe where ...
- java list<int>报错
请问一下在java中的List<int> list=new List<int>();这条语句的两个int处会报错,请问为什么? 答: 两处错误:第一:List是接口,需要实现类 ...
- TCPdump抓包命令详解--摘
http://blog.csdn.net/s_k_yliu/article/details/6665673/ http://starsliao.blog.163.com/blog/static/890 ...
- VPN服务器环境搭建
一.VPN服务器环境说明 操作系统:CentOS release 6.4 (Final) 本地网卡: 复制代码 代码如下: # ifconfig em1 Link encap:Ethernet HWa ...
- mysql默认字符集修改
(1) 最简单的修改方法,就是修改mysql的my.ini文件中的字符集键值,添加 [mysql] default-character-set = utf8 [mysqld] character_se ...
- a single statement, not multiple statements
http://dev.mysql.com/doc/refman/5.7/en/prepare.html Statement names are not case sensitive. preparab ...
- quanpailie quanbianli
#include<stdio.h>char data[5]={'a','b','c','d','e'};int vist[5]={0};char step[5]={0};char bu[5 ...