首页 > 其他 > 详细

UIButton 的基本用法

时间:2016-03-08 23:14:54      阅读:278      评论:0      收藏:0      [点我收藏+]

 

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

    }

}

 

UIButton 的基本用法

原文:http://www.cnblogs.com/tmf-4838/p/5256270.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!