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 }

效果:

IOS学习笔记(一)UIFirst

你可能感兴趣的:(first)