zoukankan      html  css  js  c++  java
  • 重写 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;

  • 相关阅读:
    Hashtable,挺爽的一个东西,大家都用烂了吧,我再画蛇添足一下。
    今天你写控件了吗?ASP.net控件开发系列(八)
    Attribute在运行期赋值?
    整几个题给大家玩玩,看看“下盘功夫”怎样
    当stringFormat碰上{和}
    一句SQL语句解决倒序数据分页提取
    C#扩展一般用于linq
    字符串转日期类型
    Dispatcher与UI线程交互
    圆形进度条
  • 原文地址:https://www.cnblogs.com/lidongxiao/p/4950001.html
Copyright © 2011-2022 走看看