zoukankan      html  css  js  c++  java
  • UIButton(在代码中使用)

    - (void)viewDidLoad {
        [super viewDidLoad];
        // 1.1 创建按钮对象
    //    UIButton *button = [[UIButton alloc] init];
        // 注意:设置按钮的类型只能在初始化的时候设置  -> UIButtonTypeCustom
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        // 1.2 设置按钮的类型
    //    button.buttonType = UIButtonTypeInfoDark;
        
        // 1.3 设置frame
        button.frame = CGRectMake(100, 100, 170, 60);
        
        // 1.4 设置背景颜色
    //    button.backgroundColor = [UIColor redColor];
    //    [button setBackgroundColor:[UIColor redColor]];
        
        // 1.5 设置文字
        // 分状态的:
    //    button.titleLabel.text = @"普通文字";
        [button setTitle:@"普通按钮" forState:UIControlStateNormal];
        [button setTitle:@"高亮按钮" forState:UIControlStateHighlighted];
        
        // 1.6 设置文字的颜色
        [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];
        
        // 1.7 设置文字的阴影颜色
        [button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        
        button.titleLabel.shadowOffset = CGSizeMake(3, 2);
        
        // 1.8 设置内容图片
        [button setImage:[UIImage imageNamed:@"player_btn_pause_normal"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"player_btn_pause_highlight"] forState:UIControlStateHighlighted];
        
    //    button.imageView.backgroundColor = [UIColor purpleColor];
        
        // 1.9 设置背景图片
        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
        
        // 2.0 加到控制器的view中
        [self.view addSubview:button];
        
        // 非常重要
        /**
         *  监听按钮的点击
         *  Target: 目标 (让谁做事情)
         *  action: 方法 (做什么事情-->方法)
         *  Events: 事件
         */
    //    SEL sel = @selector(clickButton:);
        [button addTarget:self action:@selector(demo:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    - (void)demo:(UIButton *)btn{
        NSLog(@"%@", btn);
    }
  • 相关阅读:
    论文阅记 YOLOv4: Optimal Speed and Accuracy of Object Detection
    【项目实战】yolov3-tiny人脸数据模型训练
    面试题54. 二叉搜索树的第k大节点
    102. 二叉树的层序遍历
    107. 二叉树的层次遍历 II
    连续子数组的最大和
    172. 阶乘后的零
    26 进制
    405. 数字转换为十六进制数
    504. 七进制数
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6057779.html
Copyright © 2011-2022 走看看