// 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(图片和文字混合)的更多相关文章

  1. 自定义带图片和文字的ImageTextButton

    今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...

  2. Android TextView中有图片有文字混合排列

    Android TextView中有图片有文字混合排列 1.使用html.fromHtml 2.新建ImageGetter 3.使用<img src>标签 demo: 1.设置文字 ((T ...

  3. 自定义带图片和文字的Button的排版--陈棚

    自定义button,动态加载图片与文字 [footView addSubview:btnAllChoose]; [btnAllChoose setTitle:str forState:UIContro ...

  4. 改变UIButton 图片和文字的位置

    //设置字体和图片之间的间距 _btnLeft.titleEdgeInsets = UIEdgeInsetsMake(0, -_btnLeft.imageView.frame.size.width, ...

  5. 自定义组件---图片和文字实现ImageButton效果

    1.效果图 2.自定义代码: <span style="font-family:Comic Sans MS;font-size:14px;">public class ...

  6. iOS 自定义UIButton

    工作中有一个点击button更新button上文案的需求,用自定义了button可以很简单的实现的这个需求 首先写个自定义的button CustomButton.h #import <UIKi ...

  7. h5 安卓/IOS长按图片、文字禁止选中或弹出系统菜单 的解决方法

    最近在做IM的语音功能,发现当长按录音的时候手机会弹出来系统菜单, IOS下bug形式:1)长按的标签设置为css background的形式:不会弹出菜单: 2)但是当设置为img时,系统默认识别为 ...

  8. UIButton图片与文字位置调整

    1:左图右文 默认效果就行 2:左文右图 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn addTarget:se ...

  9. ios自定义UIButton内部空间Rect

随机推荐

  1. 每天php函数 - list()给一组变量赋值

    array list ( mixed $varname [, mixed $... ] ) 像 array() 一样,这不是真正的函数,而是语言结构.list()用一步操作给一组变量进行赋值. var ...

  2. 个人翻译的cedec2010基于物理的光照

    作为自己介绍基于物理渲染计划的一部分,在自己总结和发布的同时,也会翻译一些国外的优秀资料做推广    本文是Tri Ace 在 cedec2010上发布的文章,主要描述了他们基于物理光照的实现方法,这 ...

  3. jquery 选择器,模糊匹配

    按姓名匹配 1,name前缀为aa的所有div的jquery对象 $("div[name^='aa']"); 2,name后缀为aa的所有div的jquery对象 $(" ...

  4. Java管道流

    管道流的主要作用可以用于两个线程之间的通信,有管道输出流 PipeOutputStream和管道输入流 PipeInputStream.然后通过connect将两个管道连接起来. import jav ...

  5. 【php学习】array_map,array_walk,array_filter的区别

    array_map(function($v){return $v+1;}, $array); array_walk($array, function($v, $k){...}); array_filt ...

  6. zepto源码--width,height--学习笔记

    width和height函数,实际上通过css方法也完全可以取到这两个函数的结果.获取width,$elem.css('width');设置width的话,$elem.css('width', 100 ...

  7. mysql基本sql语句大全(基础用语篇)

    1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份 ...

  8. 公共POI导出Excel方法--java

    最早开始的时候做过一些数据Excel导出的功能,但是到后期每一次导出都需要写一些差不多类似的代码,稍微研究了一下写了个公共的导出方法. 这里用的是POI,然后写成了一个公共类,传入设置好格式的数据,就 ...

  9. ECSHOP给分类添加图

    1.修改/admin/template/category_info.html <tr> <td>{$lang.cat_img}:</td> <td> & ...

  10. webView、scrollView、TableView,为了防止滚动时出现偏移,底部黑框问题等

    if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {self.automaticallyAd ...