zoukankan      html  css  js  c++  java
  • 关于UIButton的背景与标题同时显示

    setImage方法设置背景

     1         self.btnDateline=[[UIButton alloc]init];
     2         self.btnDateline.tag=tagBtnDateLine;
     3         self.btnDateline.titleLabel.font=[UIFont systemFontOfSize:18];
     4         [self.btnDateline setTitle:@"请选择" forState:UIControlStateNormal];
     5         //[self.btnDateline setBackgroundImage:_imgPicker forState:UIControlStateNormal];
     6         [self.btnDateline setImage:_imgPicker forState:UIControlStateNormal];
     7         //[self.btnDateline setBackgroundColor:[UIColor colorWithPatternImage:_imgPicker]];
     8         self.btnDateline.userInteractionEnabled=YES;
     9         [self.scrollview addSubview:self.btnDateline];
    10         [self.btnDateline addTarget:self action:@selector(btnTagged:) forControlEvents:UIControlEventTouchUpInside];

    此时图片根据button的尺寸自动进行了缩放,但遮盖了title

     

    setBackgroundColor方法

            
            self.btnDateline=[[UIButton alloc]init];
            self.btnDateline.tag=tagBtnDateLine;
            self.btnDateline.titleLabel.font=[UIFont systemFontOfSize:18];
            [self.btnDateline setTitle:@"请选择" forState:UIControlStateNormal];
            //[self.btnDateline setBackgroundImage:_imgPicker forState:UIControlStateNormal];
            //[self.btnDateline setImage:_imgPicker forState:UIControlStateNormal];
            [self.btnDateline setBackgroundColor:[UIColor colorWithPatternImage:_imgPicker]];
            self.btnDateline.userInteractionEnabled=YES;
            [self.scrollview addSubview:self.btnDateline];
            [self.btnDateline addTarget:self action:@selector(btnTagged:) forControlEvents:UIControlEventTouchUpInside];

    此时图片作为背景色,未遮盖了title,但不能根据button的尺寸自动进行了缩放

    setBackgroundImage

    self.btnDateline=[[UIButton alloc]init];
            self.btnDateline.tag=tagBtnDateLine;
            self.btnDateline.titleLabel.font=[UIFont systemFontOfSize:18];
            [self.btnDateline setTitle:@"请选择" forState:UIControlStateNormal];
            [self.btnDateline setBackgroundImage:_imgPicker forState:UIControlStateNormal];
            //[self.btnDateline setImage:_imgPicker forState:UIControlStateNormal];
            //[self.btnDateline setBackgroundColor:[UIColor colorWithPatternImage:_imgPicker]];
            self.btnDateline.userInteractionEnabled=YES;
            [self.scrollview addSubview:self.btnDateline];
            [self.btnDateline addTarget:self action:@selector(btnTagged:) forControlEvents:UIControlEventTouchUpInside];

    此时图片未遮盖了title,且也能根据button的尺寸自动进行了缩放

  • 相关阅读:
    李开复给中国学生的第一封信
    vc++学习篇(三)——预处理命令之条件编译(#ifdef,#else,#endif,#if等)
    高级程序员考试时间安排和参考书推荐
    vc++学习篇(四)—— 指针
    程序员应具备的素质
    Word 2003 长篇文档排版技巧(二)
    Google 技巧集锦
    给中国学生的第二封信
    修复mysql表
    社保相关
  • 原文地址:https://www.cnblogs.com/candr/p/3394306.html
Copyright © 2011-2022 走看看