IOS- 自定义 UIButton
#pragma mark init方法内部默认会调用initWithFrame:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// 里面的图片居中
self.imageView.contentMode = UIViewContentModeCenter;
// 里面的文字居中
self.titleLabel.textAlignment = NSTextAlignmentCenter;
// 文字字体
self.titleLabel.font = [UIFont systemFontOfSize:12];
}
return self;
}
#pragma mark 当按钮达到高亮状态的时候会调用,并且默认会在这个方法中进行高亮处理
- (void)setHighlighted:(BOOL)highlighted { }
#pragma mark 设置内部imageView的frame
- (CGRect)imageRectForContentRect:(CGRect)contentRect
{
CGFloat imgW = contentRect.size.width;
CGFloat imgH = contentRect.size.height * kImageScale;
return CGRectMake(0, 0, imgW, imgH);
}
#pragma mark 设置内部titleLabel的frame
- (CGRect)titleRectForContentRect:(CGRect)contentRect
{
CGFloat titleW = contentRect.size.width;
CGFloat titleY = contentRect.size.height * kImageScale;
CGFloat titleH = contentRect.size.height - titleY;
return CGRectMake(0, titleY, titleW, titleH);
}
IOS- 自定义 UIButton的更多相关文章
- iOS 自定义UIButton(图片和文字混合)
// UIApplicationDelegate .h文件 #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder &l ...
- iOS 自定义UIButton
工作中有一个点击button更新button上文案的需求,用自定义了button可以很简单的实现的这个需求 首先写个自定义的button CustomButton.h #import <UIKi ...
- ios自定义UIButton内部空间Rect
- IOS实现UIButton图文混排、自定义按钮按下和正常状态下不同的背景颜色、根据文字长度自定义UIButton长度
在一些项目中,我们需要自定义自己的UIButton,使Button上面同时具有图片和文字描述,实现自定义UIButton的图文混排. 首先我们需要定义一个继承自UIButton的类,同时实现自己的in ...
- 【iOS自定义键盘及键盘切换】详解
[iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...
- iOS自定义的UISwitch按钮
UISwitch开关控件 开关代替了点选框.开关是到目前为止用起来最简单的控件,不过仍然可以作一定程度的定制化. 一.创建 UISwitch* mySwitch = [[ UISwitchalloc] ...
- 如何实现 iOS 自定义状态栏
给大家介绍如何实现 iOS 自定义状态栏 Sample Code: 01 UIWindow * statusWindow = [[UIWindow alloc] initWithFrame:[UIAp ...
- iOS自定义组与组之间的距离以及视图
iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...
- iOS 自定义转场动画
代码地址如下:http://www.demodashi.com/demo/12955.html 一.总效果 本文记录分享下自定义转场动画的实现方法,具体到动画效果:新浪微博图集浏览转场效果.手势过渡动 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
随机推荐
- python简明手册学习
1.行末单独一个反斜杠表示字符串在下一行继续,而不是开始一个新的行. >>> "This is the first sentence.\ ... This is the s ...
- asp.net—缓存
1.页面缓存 要实现页面输出缓存,只要将一条 OutputCache 指令添加到页面即可. <%@ OutputCache CacheProfile=" " NoStore= ...
- PHP的 Mysqli扩展库的多语句执行
$mysqli->multi_query($sqls); 执行多个sql语句,返回true/false 有结果集时,使用 $mysqli->store_result(); 来获取结 ...
- HDOJ 4750 Count The Pairs
按边长从小到大排序...再逐个加入(就像MST一样)最先联通的点之间最长路径中的最小值就是新加入的边的长.... Count The Pairs Time Limit: 20000/10000 MS ...
- Markdown 學習
Markdown 格式由John Gruber 創建,是一種便於閱讀,非常簡潔直觀的純文本文件格式,可以方便地轉為html等其他格式,很適合與寫作,不需要關注排版問題 常用學習資源有: ###標題用 ...
- hash-4.hashtable
1.先看hashtable的源代码 public synchronized V put(K key, V value) { // Make sure the value is not null if ...
- Promise 原理探究及其简单实现
可移步 http://donglegend.com/2016/09/11/promise%E5%8E%9F%E7%90%86%E6%8E%A2%E7%A9%B6/ 观看 Promise是个什么玩意,大 ...
- codemirror和ace editor的语法高亮
两个javascript库用做在线代码编辑器都是非常优秀的选择 我这两天对这两个类库做了简单的研究,重点是语法高亮的自定义: ace editor的主要思路是生成状态机,从一个startstate开始 ...
- sizeof和小部分c++语法
ios 中 sizeof(类型) 获取类型所占字节 32位操作系统中, 每个字节占8个位 64位操作系统中, 每个字节占16个位 INT_MAX 2147483647 int size1 = siz ...
- XSS Filter绕过
之前挖到某金融网站的xss 但是困于xss filter无奈不好下手.只能在火狐下弹窗. 以下该图是我的测试. 后来发给一个Invoker哥们儿.成功给我发来payload成功绕过了XSS Filte ...