UI02_UIButton

import “AppDelegate.h”

@interface AppDelegate ()

@property(nonatomic, assign)BOOL isSelected;
@property(nonatomic, retain)UITextField *textField;

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [_textField 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];
    [_window release];


// 创建一个Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 150, 50);
[self.window addSubview:button];

// 添加边框,添加弧度
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;

// 添加一个标题
// [button setTitle:@"确认" forState:UIControlStateNormal];
// 修改字体大小
// button.titleLabel.font = [UIFont systemFontOfSize:25];
// 修改颜色
// [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

// button上添加图片
// 全铺
// [button setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
// [button setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

// 绑定一个点击方法
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

// 创建一个textField
 self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 200, 150, 50)];
    self.textField.layer.borderWidth = 1;
    self.textField.layer.cornerRadius = 10;
    [self.window addSubview:self.textField];
    [_textField release];

   self.textField.secureTextEntry = YES;
    改变textfiled的SecureTextEntry属性时,给textfiled重新赋值

return YES;
}
// 点击return 回收键盘
- (BOOL)textFieldShoudReturn:(UITextField *)textField {
// 失去第一响应者
[textField resignFirstResponder];
return YES;
}
- (void)click:(UIButton *)button{
 NSLog(@"%@", self.textField.text);
 if ([button.currentTitle isEqualToString:@"确认"]) {
    [button setTitle@"取消" forState:UIControlStateNormal];}
 else {
    [button setTitle:@"确认" forState:UIControlStateNormal];}
self.textField.secureTextEntry = !self.textField.secureTextEntry;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值