zoukankan      html  css  js  c++  java
  • uibutton的常用属性

    //UIButton
        UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
        button.frame=CGRectMake(100, 100, 100, 100);
        button.backgroundColor=[UIColor yellowColor];
        
        //外观控制
        [button setTitle:@"按钮" forState:UIControlStateNormal];
        
        
        //加背景
       // [button setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
        
        //设置文字颜色
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            //第二种改变字体颜色方法
        button.tintColor=[UIColor blackColor];//渲染颜色
        
        //响应事件
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [bgView addSubview:button];
        [bgView release];
        

    //设置
        //文字
        [button setTitle:@"按钮" forState:UIControlStateNormal];
        //文字颜色
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        //背景图片
        [button setBackgroundImage:[UIImage imageNamed:@"1.pug"] forState:UIControlStateNormal];
        //添加事件
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        //添加前景图片(需要镂空png图片)
        [button setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];
        
        //获取button上的文字
        NSString *butString = [button titleForState:UIControlStateNormal];
        NSLog(@"文字:%@",butString);
        //获取button上文字的颜色
        UIColor *buttonColor = [button titleColorForState:UIControlStateNormal];
        NSLog(@"%@",buttonColor);
        //获取前景图片
        UIImage *buttonImage = [button imageForState:UIControlStateNormal];
        //获取背景图片
        UIImage *butBgImage = [button backgroundImageForState:UIControlStateNormal];
        
        [self.window addSubview:button];
        [bgview release];
        
        */
        

  • 相关阅读:
    Metabase研究 开源的数据报表
    Redis配置不当致使root被提权漏洞
    一个程序员被骗去养猪
    调度器简介,以及Linux的调度策略
    Linux的内存分页管理
    在地铁11号线上写书
    为什么说“概率”带来一场现代革命?
    快速学习Bash
    用树莓派玩转蓝牙
    树莓派的GPIO编程
  • 原文地址:https://www.cnblogs.com/-ios/p/4672587.html
Copyright © 2011-2022 走看看