zoukankan      html  css  js  c++  java
  • UI基础 Button

    UIButton

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        //按钮
    //    UIButton* button=[[UIButton alloc]initWithFrame:<#(CGRect)#>]
        UIButton* button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.backgroundColor=[UIColor yellowColor];
        [self.view addSubview:button];
        //指定位置大小
        button.frame=CGRectMake(50, 100, 300, 300);
        //设置按钮文字
        [button setTitle:@"淘宝" forState:UIControlStateNormal];
        //设置按钮颜色
        [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        //背景图片
        //创建一张图片
    //    UIImage* image=[UIImage imageNamed:@"a.jpg"];
    //    [button setBackgroundImage:image forState:UIControlStateNormal];
    //    //前景图片
    //    [button setImage:[UIImage imageNamed:@"b.jpg"] forState:UIControlStateNormal];
        
        //调整文字和图片位置
        [button setImageEdgeInsets:UIEdgeInsetsMake(0, -30, 0, 0)];
        [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
        
        //添加点击事件
        [button addTarget:self action:@selector(youTouchMe) forControlEvents:UIControlEventTouchUpInside];
        
        
        
    
    }
    -(void)youTouchMe
    {
        NSLog(@"你点了我");
        
        
    }
    @end
  • 相关阅读:
    正则表达式体会
    checkbox、全选反选,获取值
    弹出窗体值回调
    页面点击任意js事件,触发360、IE浏览器新页面
    XML增、删、改
    面试题
    行列转换
    DataTable 和Json 字符串互转
    前台js与后台方法互调
    文件与base64二进制转换
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13302524.html
Copyright © 2011-2022 走看看