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
随机推荐
- Sql Group by 使用
CREATE TABLE StuCourseScore ( ID int, Name nvarchar(10), Course nvarchar(10), Score int ) INSERT Stu ...
- php连接redis数据库 操作redis任务队列
首先你的安装phpredis扩展在你的服务器上 $redis = new Redis(); $redis->connect('119.29.10.xx',6379); $redis->au ...
- 用MSoffice里的绘图工具
试过一些绘图表的工具,在xbeta推荐的替代visio一文中介绍的一些软件.之前用得最多的就是Dia,在linux下也有.现在才发现在微软的office下的绘图工具已经足够我使用了,不需要专业的图形符 ...
- Nginx 配置 Basic 认证
/* * 环境:LNMP(CentOS 6.6 + Nginx 1.8.0) */ 在 Nginx 下配置 Basic 认证需要依靠 Nginx 的 http_auth_basic_module 模块 ...
- php + ajax + html 简单跨域问题
XMLHttpRequest cannot load http://localhost:8080/abc/index.php. No 'Access-Control-Allow-Origin' hea ...
- phpcms v9 模板调用代码大全
另:每个栏目会对应当前所选模型的三个模板文件: 这些模板文件所在位置:phpcms/templates/default/content/ 目录下,如果想修改模板文件,只需要到此目录下找到对应的模板文 ...
- NSURLSession
参考文章1, apple文档 一.NSURLSessionConfiguration 介绍:分别配置每一个 session 对象.(NSURLConnection 很难做到) 分类: 1) defau ...
- 使用C++还是QML
本质上,Qt 是一个C++类库.在引入 QML 以前,所有的开发都是基于 C++ 的,但到了 Qt 5,QML 和 Qt Quick 成为了 Qt 的核心之一,导致很多初学者在犹豫是否还需要学习 C+ ...
- 完美解决 .txt文件在Mac上不能打开的问题
- Mac版 MicrosoftOffice2015 办公软件 破解教程
来自:http://bbs.feng.com/read-htm-tid-9704285.html 下载链接:http://pan.baidu.com/s/1dD6lBFz 提取密码:xu5n 补丁: ...