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
随机推荐
- jQuery系列:N种方法大总结
jquery自定义属性,区分prop()和attr() jQueryObject.prop( propertyName [, value ] ):为添加,获取属性(property),并非attrib ...
- nginx支持flv MP4 扩展nginx_mod_h264_streaming,nginx-rtmp-module-master,yamdi
./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/nginx/sbin/nginx \ --conf-path=/usr ...
- 将request.getParameterMap()转换成可操作的普通Map
在java web项目中虽然可以通过request.getParameterMap()很轻松的获得参数Map,但得到的Map和普通Map是不一样的,是被锁定的,不能像操作常规Map那样进行put.ge ...
- Mac OS 快捷键
系统 (Option+) Command+Space 切换输入法 Command+Tab 切换不同应用 Command+Tab 切换一个应用内的不同窗口 Command+Shift+3 截取整个屏幕 ...
- [Albert 朗读行动记录贴]采纳Scalers方法:口语成长行动
目标:100小时成长计划,持续朗读录音100小时. 行动计划:每天点评美音3个人的朗读,英音1个. 完成朗读计划,录一段.附录一段.1分半左右. 开始日期:3月18日 原帖: [335][合辑]Sca ...
- [听点音乐]Mozart's 'The Marriage of Figaro'
今天看到西雅图图书馆上写着可以到当地图书馆欣赏Mozart's 'The Marriage of Figaro'.查了一下,貌似还挺好看. “ Preview lecture of Seattle O ...
- 后台list 如何转换为json格式
request.setCharacterEncoding("utf-8"); response.setCharacterEncoding( "UTF-8"); ...
- ext在web工程目录导致myeclipse内存溢出问题
分类: Extjs2013-01-24 00:01 2068人阅读 评论(2) 收藏 举报 当在eclipse中的web工程中增加了extjs4,出现An internal error occurre ...
- Arrays.toString Arrays.asList
import java.util.Arrays; public class TestCalc{ public static void main(String[] args) { ,,,,,,,}; / ...
- jquery的$.ajax async使用详解
async在jquery ajax中是一个同步参数了,我们下面来给大家介绍在jquery ajax中使用async时碰到的一些问题与方法介绍,希望例子能给各位同学带来一些帮助哦. async默 ...