重写 button 的创建方法
重写 button 的创建方法
//sxc时时改变
// self.videoM.progress = progress;
// if ([self.videoM.downloadStr
isEqualToString:@"100%"]) {
// self.downloadBtn.titleLabel.
text = @"已缓存";
// }else{
// self.downloadBtn.titleLabel.text
= self.videoM.downloadStr;
// NSLog(@"%@=---------",self.v
ideoM.downloadStr);
// }//有两种重写方法,主要看你想怎么去创建
这个button
-(void)setFrame:(CGRect)frame
{
[super setFrame:frame];
[self.icon removeFromSuperview];
[self.textLabel removeFromSuperview];
[self.iconSelected
removeFromSuperview];
//创建一个正方形 的imageView (只读的不能
self. set方法不可以)
_icon= [[UIImageViewalloc]
initWithFrame:CGRectMake(0, 0,
frame.size.height, frame.size.height)];
[self addSubview:self.icon];
_iconSelected= [[UIImageViewalloc]
initWithFrame:self.icon.bounds];
self.iconSelected.hidden = YES;
[self addSubview:self.iconSelected];
_textLabel= [[UILabelalloc]
initWithFrame:CGRectMake(frame.size.height,
0, frame.size.width- frame.size.height,
frame.size.height)];
_textLabel.textColor= [UIColor
whiteColor];
_textLabel.font= [UIFont
systemFontOfSize:14];
[self addSubview:self.textLabel];
//第二种
//装逼的创建方法 只执行一次,单例方法也可用
//
//
//
initWithFrame:CGRectMake(0, 0,
frame.size.height, frame.size.height)];
// [self addSubview:self.icon];
////
// _textLabel = [[UILabel alloc]
initWithFrame:CGRectMake(frame.size.height,
0, frame.size.width - frame.size.height,
frame.size.height)];
// [self
addSubview:self.textLabel];
//
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_icon = [[UIImageView alloc]
// });
}
#pragma mark 重写selected方法,做图片更换
- (void)setSelected:(BOOL)selected
{
//父类怎么做 还怎么做我们只是在它原有的基础
上添加自己的方法
[super setSelected:selected];
//根据selected属性对图片做修改
if(selected) {
self.iconSelected.hidden = NO;
self.icon.hidden = YES;
}else
{
self.iconSelected.hidden = YES;
self.icon.hidden = NO;
}
}
//使用alloc创建
-
(instancetype)initWithFrame:(CGRect)frame
{
self= [superinitWithFrame:frame];
if(self) {
}
return self;
}
重写 button 的创建方法的更多相关文章
- 为什么要重写 hashcode 和 equals 方法?
引言 以前面试的时候被面试官问到过这样一个问题: 你有没有重写过 hashCode 方法? 心里想着我没事重写哪玩意干啥,能不写就不写.嘴上当然没敢这么说,只能略表遗憾的说抱歉,我没写过. 撇了面试官 ...
- 为什么要重写hashcode和equals方法?初级程序员在面试中很少能说清楚。
我在面试 Java初级开发的时候,经常会问:你有没有重写过hashcode方法?不少候选人直接说没写过.我就想,或许真的没写过,于是就再通过一个问题确认:你在用HashMap的时候,键(Key)部分, ...
- 为什么要重写equals和hashcode方法
equals hashcode 当新建一个java类时,需要重写equals和hashcode方法,大家都知道!但是,为什么要重写呢? 需要保证对象调用equals方法为true时,hashcode ...
- (转)为什么要重写 hashcode 和 equals 方法?
作者丨hsm_computer cnblogs.com/JavaArchitect/p/10474448.html 我在面试Java初级开发的时候,经常会问:你有没有重写过hashcode方法?不少候 ...
- 同过增强Connection类[重写了close的方法]实现的从连接池取出连接并放回连接的简单的实现流程
package tk.dong.connection.util; import java.io.IOException;import java.io.InputStream;import java.i ...
- Thread之六:线程创建方法
1.继承Thread类,重写该类的run()方法. 2.实现Runnable接口,并重写该接口的run()方法,该run()方法同样是线程执行体,创建Runnable实现类的实例,并以此实例作为Thr ...
- [Xcode 实际操作]九、实用进阶-(19)重写父类的绘图方法,使用图形上下文绘制自定义图形
目录:[Swift]Xcode实际操作 本文将演示如何使用图形上下文,绘制自定义图形. 使用快捷键[Command]+[N]创建一个新的类文件. (在项目文件夹[DemoApp]上点击鼠标右键[New ...
- 为什么要重写hashcode和equals方法
我在面试 Java初级开发的时候,经常会问:你有没有重写过hashcode方法?不少候选人直接说没写过.我就想,或许真的没写过,于是就再通过一个问题确认:你在用HashMap的时候,键(Key)部分, ...
- 内存泄漏避雷!你真的了解重写equals()和hashcode()方法的原因吗?
基本概念 要比较两个对象是否相等时需要调用对象的equals() 方法: 判断对象引用所指向的对象地址是否相等 对象地址相等时, 那么对象相关的数据也相等,包括: 对象句柄 对象头 对象实例数据 对象 ...
随机推荐
- c function
/* #include<stdio.h> int is_prime(int n) { for(int i = 2; i <= n/2; i ++) if(n % 2 == 0) re ...
- UVA 11468【AC自动机+DP】
dp[i][j]表示走了i步走到j结点的概率.初始值dp[0][0] = 1.当走到的结点不是单词尾结点时,才能走过去. !end[i]&&last[i] == root时,该结点才可 ...
- maven setting.xml配置说明
文件存放位置 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ${user.home}/.m2/settings.xml note:用户配置优先于全局配置.${use ...
- .net ftp上传文件方法
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...
- tracert 命令详解
tracert 命令详解 How to Use the TRACERT Utility The TRACERT diagnostic utility determines the route to a ...
- hdu 4055 && hdu 4489 动态规划
hdu 4055: 一开始我想的递推方向想得很复杂,看了别人的博客后才醍醐灌顶: 参照他的思路和代码: #include<cstdio> #include<cstring> # ...
- CSS3_边框属性之圆角的基本图形案例
一.正方形 div{ background:#F00; width:100px; height:100px;} 二.长方形 div{background:#F00;width:200px;heig ...
- phalcon: 获取参数的方法
phalcon: 获取参数的方法 一般情况下:GET/POST $this->request->get(参数); $this->request->getPost("参 ...
- #Javascript:this用法整理
常用Javascript的人都知道,[this這個關鍵字在一個函式內究竟指向誰]的這個問題很令人頭大,本人在這裡整理了一下Javascript中this的指向的五種不同情況,其中前三種屬於基本的情況, ...
- Servlet的尾(yi)巴---filter ( 过滤器 )的小应用
该,该,该.......,继之前说到的 Filter 现在用这个来做一个小小的应用----------> 铛,铛,铛,铛..... ->_-> <丑逼的留言板&g ...