#import "AppDelegate.h"
@interface AppDelegate ()
12.创建一个textField的属性
@property(nonatomic, retain)UITextField *textField;
@end
@implementation AppDelegate
1.添加dealloc方法.
- (void)dealloc
{
[_textField release];
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
2.[_window release];
3.用button自己的遍历构造器方式来创建对象,不需要释放;(如果用alloc来创建button,系统默认为custom(如何判断为custom,用button中的buttonType属性来判断,custom为0,system为1),必须要设置标题颜色,才能显示标题的内容,否则只设置标题,不设置颜色,不能显示标题内容).
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
4.指定button的位置和大小.
button.frame = CGRectMake(100, 100, 200, 70);
5.设置背景颜色.
button.backgroundColor = [UIColor yellowColor];
button.layer.borderColor = [UIColor redColor].CGColor;
[self.window addSubview:button];
6.给button设置标题.
[button setTitle:@"确认" forState:UIControlStateNormal];
7.设置按钮标题的字体大小.
button.titleLabel.font = [UIFont systemFontOfSize:20];
8.修改颜色
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
9.设置圆角.
button.layer.cornerRadius = 10;
10.设置边框.
button.layer.borderWidth = 1;
11.给button绑定一个点击方法.
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
13.创建一个textField
self.textField = [UITextField alloc] initWithFrame:CGRectMake(100, 200, 150, 50);
self.textField.backgroundColor = [UIColor cyanColor];
self.textField.layer.borderWidth = 1;
self.textField.layer.cornerRaius = 10;
self.textField.textColor = [UIColor blackColor];
[self.window addSubview:self.textField];
[_textField release];
14.使密码不可见.
self.textField.secureTextEntry = YES;
return YES;
}
15.添加测试点击按钮的方法.
- (void)click:(UIButton *)button {
if ([button.currentTitle isEqualToString:@"确认"]) {
[button setTitle:@"取消" forState:UIControlStateNormal];
} else {
[button setTitle:@"确认" forState:UIControlStateNormal];
}
self.textField.secureTextEntry = !self.textField.secureTextEntry;
}
@end