zoukankan      html  css  js  c++  java
  • UIButton 的基本用法

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    @property(strong,nonatomic) UIButton *btnTest;

    @property(strong,nonatomic) UITextField *txtName;

    @end

    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        

        self.btnTest=[UIButton buttonWithType:UIButtonTypeRoundedRect];

        self.btnTest.frame=CGRectMake(100, 100, 150, 44);

        [self.btnTest setTitle:@"按钮" forState:UIControlStateNormal];

        

        [self.btnTest setBackgroundColor:[UIColor redColor]];

        [self.btnTest addTarget:self action:@selector(testBtn) forControlEvents:UIControlEventTouchCancel];

        [self.view addSubview:self.btnTest];

        

    }

    -(void)testBtn

    {

        NSString *name=self.txtName.text;

        NSLog(@"%@",name);

        NSLog(@"test");

        int len=(int)self.txtName.text.length;

        

        if (len==0)

        {

            NSLog(@"用户名不能为空");

        }

        else if (len>0&&len<8)

        {

            NSLog(@"长度不够");

        }

        else

        {

            NSLog(@"继续");

        }

    }

  • 相关阅读:
    ubuntu安装node.js+express+mongodb
    Linux(Ubuntu)下安装NodeJs
    Nodejs的Express完成安装指导
    【详解】ERP、APS与MES系统是什么?
    linux常用命令
    Linux命令集合
    sql 以逗号分割成多行数据
    【项目管理工具】SVN
    富文本编辑器
    cookie的跨页面传值
  • 原文地址:https://www.cnblogs.com/tmf-4838/p/5256270.html
Copyright © 2011-2022 走看看