• IOS学习笔记(一)UIFirst


     1 @interface HelloNameAppDelegate : UIResponder <UIApplicationDelegate> 
     2 {
     3     UITextField *_firstNumTF;//TF是textfield的缩写
     4     UITextField *_secondNumTF;
     5     UILabel *_resultLable;
     6     //UIButton *_calculateBT;
     7 }
     8 @property (strong, nonatomic) UIWindow *window;
     9 
    10 @end
    .m代码
     1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     2 {
     3     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
     4     // Override point for customization after application launch.
     5     self.window.backgroundColor = [UIColor grayColor];
     6     
     7     //UItextFiled 用于接受用户(少量文字)的UI控件
     8     _firstNumTF = [[UITextField alloc]initWithFrame:CGRectMake(10, 50, 80, 30)];
     9     _firstNumTF.borderStyle = UITextBorderStyleRoundedRect;//边框类型
    10     _firstNumTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;//垂直方向居中对齐
    11     _firstNumTF.clearsOnBeginEditing = NO;//带ing的属性值一般是BOOL型,重新编辑时是否重新呼出键盘
    12     _firstNumTF.keyboardType = UIKeyboardTypeNumberPad;//键盘类型
    13     _firstNumTF.autocapitalizationType = UITextAutocapitalizationTypeNone;//首字母自动大小写
    14     _firstNumTF.autocorrectionType = UITextAutocorrectionTypeNo;//自动纠错
    15     _firstNumTF.textAlignment = UITextAlignmentRight;
    16     //_firstNumTF.a
    17     [self.window addSubview:_firstNumTF];
    18     
    19     UILabel *addLable = [[UILabel alloc]initWithFrame:CGRectMake(90, 50, 30, 30)];
    20     addLable.text = @"+";
    21     addLable.font = [UIFont fontWithName:@"BodoniOrnamentsITCTT" size:30];
    22     addLable.textAlignment = UITextAlignmentCenter;
    23     addLable.textColor = [UIColor orangeColor];
    24     addLable.backgroundColor = [UIColor clearColor];//背景色通常设置为clearColor
    25     [self.window addSubview:addLable];
    26     
    27     _secondNumTF = [[UITextField alloc]initWithFrame:CGRectMake(120, 50, 80, 30)];
    28     _secondNumTF.borderStyle = UITextBorderStyleRoundedRect;
    29     [self.window addSubview:_secondNumTF];
    30     
    31     UILabel *equalLable = [[UILabel alloc]initWithFrame:CGRectMake(200, 50, 30, 30 )];
    32     equalLable.text = @"=";
    33     equalLable.font = [UIFont fontWithName:@"BodoniOrnamentsITCTT" size:30];
    34     equalLable.textAlignment = UITextAlignmentCenter;
    35     equalLable.textColor = [UIColor orangeColor];
    36     equalLable.backgroundColor = [UIColor purpleColor];
    37     equalLable.shadowColor = [UIColor blueColor];//阴影颜色
    38     equalLable.shadowOffset = CGSizeMake(5, 5);//阴影偏移,向右,向下偏为正数
    39     [self.window addSubview:equalLable];
    40     
    41     _resultLable = [[UILabel alloc]initWithFrame:CGRectMake(230, 50, 80, 30)];
    42     _resultLable.text = @"";
    43     [self.window addSubview:_resultLable];
    44     //button本身包含UIImage UIButton UIImage三层
    45     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    46     button.frame = CGRectMake(100, 100, 120, 40);
    47     [button setTitle:@"计算" forState:UIControlStateNormal];
    48     [button setTitle:@"BINGGO" forState:UIControlStateHighlighted];
    49     [button addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
    50     [self.window addSubview:button];
    51     
    52     [self.window makeKeyAndVisible];
    53     return YES;
    54 }
    55 
    56 -(void)buttonTapped
    57 {
    58     float first = [_firstNumTF.text floatValue];
    59     float second = [_secondNumTF.text floatValue];
    60     float result = first + second;
    61     _resultLable.text = [NSString stringWithFormat:@"%g",result];//浮点数结果 去掉后面无意义的0
    62     //[_firstNumTF resignFirstResponder];//取消第一响应者,回收键盘
    63     //[_secondNumTF resignFirstResponder];//取消第一响应者
    64    // UITextFieldDelegate
    65 }

    效果:

  • 相关阅读:
    jQuery $.each用法
    JSON.parse()和JSON.stringify()
    创建对象,初始化对象属性,给节点分派一个合成事件
    javascript 兼容W3c和IE的添加(取消)事件监听方法
    tomcat发布后项目classes下无编译文件
    纯css实现计数器效果
    js点击元素输出对应的index
    鼠标滚轮监听防“抖动”
    原生dom的querySelector、querySelectorAll方法
    spring mvc 通过url传来的参数乱码的解决方法
  • 原文地址:https://www.cnblogs.com/worldtraveler/p/2687787.html
Copyright © 2020-2023  润新知