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(@"继续");
}
}
@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(@"继续");
}
}
相关文章推荐
- 21. 手势识别之UITapGestureRecognizer
- 去掉UItableview headerview黏性(sticky)
- ***LeetCode 95. Unique Binary Search Trees II
- IOS-UITableViewStyle设置Group、Plain问题
- UI笔记2
- UITextView实现图文混排效果
- 20. 手势识别之UISwipeGestureRecognizer
- UI控件
- ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- 动态规划 Common Subsequence
- UI控件闪灯
- HashMap HashTable ConcurrentHashMap key和value是否可以null的问题 源码分析
- ios UI数据库 sqlite小型数据库的增、删、改、查、排序
- UITextView 文本垂直居中
- 从NavigationController 下的UITableView中移除 header
- 创建型模式 --- 建造者模式(Builder)
- C# 并发队列ConcurrentQueue
- Invalid layout of java.lang.String at value Error occurred during initialization of VM Invalid layou
- Guided Filter 引导滤波
- 19.原谅我还说iOS7,自定义转场动画与topLayoutGuide在iOS7中的bug