// 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. html5:服务器事件推送(server-sent events)Asp.net

    支持 不支持IE 个人理解说明 个人理解:这种消息推送方式不太推广,原因有以下三点~~~`我怎么老是学这些自己认为不会推广的东西呢~汗 在.net中,framework4.5以上就可以由SignalR ...

  2. PHP 面试题数组篇[ 整理中 ]

    网上找的PHP数组题,准备自己做一遍并且记录下来.不断添加中. 1.写函数创建长度为10的数组,数组中的元素为递增的奇数,首项为1. <?php function arrsort($first, ...

  3. CentOS安装TortoiseSVN svn 客户端

    CentOS安装TortoiseSVN svn 客户端   一.CentOS安装TortoiseSVN yum install -y subversion 二.SVN客户端命令 1.查看帮助 命令:s ...

  4. unity HideInInspector与SerializeField

    [HideInInspector]表示将原本显示在面板上的序列化值隐藏起来. [SerializeField]表示将原本不会被序列化的私有变量和保护变量可以序列化,这么他们在下次读取时,就是你上次赋值 ...

  5. java 客户端获取真实ip地址

    在开发工作中,我们常常需要获取客户端的IP.一般获取客户端的IP地址的方法是:request.getRemoteAddr();但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实 ...

  6. NSUserdefaults 简介以及存储自定义数据类型的方法

    一.了解NSUserDefaults以及它可以直接存储的类型 NSUserDefaults是一个单例,在整个程序中只有一个实例对象,他可以用于数据的永久保存,而且简单实用,这是它可以让数据自由传递的一 ...

  7. alibaba的FastJson(高性能JSON开发包)

    这是关于FastJson的一个使用Demo,在Java环境下验证的 class User{ private int id; private String name; public int getId( ...

  8. linux与linux,linux与windows之间用SSH传输文件

    linux与linux,linux与windows之间用SSH传输文件linux与linux之间传送文件:scp file username@hostIP:文件地址    例: scp abc.txt ...

  9. [LeetCode]题解(python):089 Gray Code

    题目来源 https://leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two suc ...

  10. Android笔记: Android版本号

    由于有2套版本号 总是对应不准 记下来做过标记 Android 4.3 ----18 Android 4.2---17 Android 4.1---16 Android 4.0.3---15Andro ...