zoukankan      html  css  js  c++  java
  • iOS-动态创建按钮

    //
    //  ViewController.m
    //  动态创建按钮
    //
    //  Created by YaguangZhu on 15/7/29.
    //  Copyright (c) 2015年 YaguangZhu. All rights reserved.
    //
    
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        //UIButton *button = [[UIButton alloc] init];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        [button setTitle:@"hdhdh" forState:UIControlStateNormal];
        [button setTitle:@"sss" forState:UIControlStateHighlighted];
        
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
        
        UIImage *imgNormal = [UIImage imageNamed:@"01"];
        UIImage *imgHigh = [UIImage imageNamed:@"02"];
        
        [button setBackgroundImage:(imgNormal ) forState:UIControlStateNormal];
        [button setBackgroundImage:(imgHigh) forState:UIControlStateHighlighted];
        
        button.frame = CGRectMake(50, 100, 100, 100);
        //单击事件
        [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:button];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)buttonClick
    {
        NSLog(@"ssss");
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end
  • 相关阅读:
    Hamming Distance(随机算法)
    Difference Between Primes
    Pet(dfs)
    29. Divide Two Integers
    28. Implement strStr()
    25. Reverse Nodes in k-Group
    24. Swap Nodes in Pairs
    23. Merge k Sorted Lists
    22. Generate Parentheses
    19. Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4685769.html
Copyright © 2011-2022 走看看