UI04_UIButton

#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]];
    // Override point for customization after application launch.
    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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值