您的位置:首页 > 产品设计 > UI/UE

UIButton 的基本用法

2016-03-08 22:42 344 查看
#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(@"继续");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: