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(@"继续");

        }

    }

  • 相关阅读:
    计算两个经纬度之间的距离,单位米
    PHP获取汉字首字母函数
    tp3.2 上传文件及下载文件
    最少知识原则
    单一职责原则
    接口和面向接口编程
    开放-封闭原则
    设计原则
    websrom编译器
    头条笔试题2018后端第二批-用户喜好
  • 原文地址:https://www.cnblogs.com/tmf-4838/p/5256270.html
Copyright © 2011-2022 走看看