zoukankan      html  css  js  c++  java
  • iOS基础控件随笔代码

    UIViewController的生命周期:

    1、运行APP

    2、-  (void)loadView

    {

      [super loadView];

    }

    3、- (void)viewDidLoad

    {

      [super viewDidLoad];

    }

    4、- (void)viewWillAppear:(BOOL)animated

    {

      [super viewWillAppear:animated];

    }

    5、 - (void)viewDidAppear:(BOOL)animated

    {

      [super viewDidAppear:animated];

    }

    6、 - (void)viewWillDisappear:(BOOL)animated

    {

      [super viewWillDisappear:animated];

    }

    7、 - (void)viewDidDisappear:(BOOL)animated

    {

      [super viewDidDisappear:animated];

    }

    8、- (void)didReceiveMemoryWarning

    {

      [super didReceiveMemoryWarning];

    }

     1 UILabel标签:
     2 
     3 #import <UIKit/UIKit.h>
     4 
     5 @interface FirstViewController : UIViewController
     6 
     7 @property (nonatomic, strong) UILabel *label;
     8 
     9 @end
    10 
    11 
    12 - (void)viewDidLoad
    13 {
    14     [super viewDidLoad];
    15     _label =[[UILabel alloc] initWithFrame:CGRectMake(100, 50, 220, 40)];
    16     _label.text = @"欢迎大家学习ios软件开发";
    17     _label.textColor = [UIColor redColor];
    18     [self.view addSubview:_label];
    19     
    20 }
     1 UIButton和UILable交互
     2 
     3 #import "FirstViewController.h"
     4 #import "GlobalDefine.h"
     5 #import "SecondViewController.h"
     6 
     7 @interface FirstViewController ()
     8 
     9 @end
    10 
    11 @implementation FirstViewController
    12 
    13 - (void)loadView
    14 {
    15     [super loadView];
    16 
    17 }
    18 
    19 - (void)viewDidLoad
    20 {
    21     [super viewDidLoad];
    22     _label =[[UILabel alloc] initWithFrame:CGRectMake(100, 50, 220, 40)];
    23     _label.text = @"欢迎大家学习ios软件开发";
    24     _label.tag = 1;
    25     _label.textColor = [UIColor redColor];
    26     [self.view addSubview:_label];
    27     
    28     UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    29     button.frame = CGRectMake(SCREENWIDTH - 90, SCREENHEIGHT - 60, 80, 40);
    30     [button setTitle:@"下一页" forState:UIControlStateNormal];
    31     [self.view addSubview:button];
    32     
    33     //跳转
    34     [button addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    35 }
    36 
    37 - (void)next:(id)sender
    38 {
    39     SecondViewController *tempVC = [[SecondViewController alloc] init];
    40     
    41     [self presentViewController:tempVC animated:YES completion:nil];
    42 }
    43 
    44 - (void)viewWillAppear:(BOOL)animated
    45 {
    46     [super viewWillAppear:animated];
    47     if (_label.tag != 1)
    48     {
    49         _label.text = @"HAHAHAHA";
    50     }
    51     else
    52         _label.tag = 0;
    53     
    54 }
    55 
    56 #import "SecondViewController.h"
    57 #import "GlobalDefine.h"
    58 
    59 @interface SecondViewController ()
    60 
    61 @end
    62 
    63 @implementation SecondViewController
    64 
    65 - (void)viewDidLoad {
    66     [super viewDidLoad];
    67 
    68     
    69     UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    70     button.frame = CGRectMake(20, 20, 50, 40);
    71     [button setTitle:@"返回" forState:UIControlStateNormal];
    72     
    73     [button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    74     
    75     [self.view addSubview:button];
    76     
    77     //跳转
    78     [button addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
    79 }
    80 
    81 - (void)next:(id)sender
    82 {
    83     
    84     [self dismissViewControllerAnimated:YES completion:nil];
    85 }
      1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      2     
      3     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      4     self.window.rootViewController = [[ViewController alloc] init];
      5     self.window.backgroundColor = [UIColor grayColor];
      6     [self.window makeKeyAndVisible];
      7     
      8     return YES;
      9 }
     10 
     11 #import <UIKit/UIKit.h>
     12 
     13 @interface ViewController : UIViewController
     14 
     15 @property (nonatomic, strong) UILabel *label;
     16 @property (nonatomic, strong) UIButton *button;
     17 
     18 @end
     19 
     20 #import "ViewController.h"
     21 #import "GlobalDefine.h"
     22 #import "SecondViewController.h"
     23 
     24 @interface ViewController ()
     25 
     26 @end
     27 
     28 @implementation ViewController
     29 
     30 - (void)viewDidLoad
     31 {
     32     [super viewDidLoad];
     33     _label = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH / 2 - 150, SCREENHEIGHT / 2 - 15, 300, 30)];
     34     _label.text = @"北京,你好!HELLO";
     35     _label.tag = 1;
     36     _label.textColor = [UIColor whiteColor];
     37     _label.font = [UIFont systemFontOfSize:22];
     38     _label.font = [UIFont boldSystemFontOfSize:23];
     39     _label.font = [UIFont italicSystemFontOfSize:25];
     40     _label.textAlignment = NSTextAlignmentCenter;
     41     [self.view addSubview:_label];
     42     
     43     _button = [UIButton buttonWithType:UIButtonTypeSystem];
     44     [_button setTitle:@"Next" forState:UIControlStateNormal];
     45     _button.frame = CGRectMake(SCREENWIDTH - 80, SCREENHEIGHT - 50, 60, 30);
     46     [_button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
     47     _button.titleLabel.font = [UIFont systemFontOfSize:20];//设置按钮字体大小
     48     [self.view addSubview:_button];
     49     
     50     //跳转
     51     [_button addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
     52 }
     53 
     54 - (void)next:(id)sender
     55 {
     56     SecondViewController *tempVC = [[SecondViewController alloc] init];
     57     [self presentViewController:tempVC animated:YES completion:nil];
     58 }
     59 
     60 - (void)viewWillAppear:(BOOL)animated
     61 {
     62     if (_label.tag != 1)
     63     {
     64         _label.text = @"VIP";
     65     }
     66     else
     67     {
     68         _label.tag = 0;
     69     }
     70 }
     71 
     72 - (void)didReceiveMemoryWarning {
     73     [super didReceiveMemoryWarning];
     74     // Dispose of any resources that can be recreated.
     75 }
     76 
     77 @end
     78 
     79 #import "SecondViewController.h"
     80 #import "GlobalDefine.h"
     81 
     82 @interface SecondViewController ()
     83 
     84 @end
     85 
     86 @implementation SecondViewController
     87 
     88 - (void)viewDidLoad {
     89     [super viewDidLoad];
     90     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(SCREENWIDTH / 2 - 130, SCREENHEIGHT / 2 - 20, 260, 40)];
     91     label.font = [UIFont systemFontOfSize:21];
     92     label.text = @"IOS is so easy! most of practice";
     93     label.textColor = [UIColor greenColor];
     94     [self.view addSubview:label];
     95     
     96     UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
     97     button.frame = CGRectMake(SCREENWIDTH - 100, SCREENHEIGHT - 50, 80, 30);
     98     [button setTitle:@"返回" forState:UIControlStateNormal];
     99     [button setTintColor:[UIColor whiteColor]];
    100     button.titleLabel.font = [UIFont systemFontOfSize:16];
    101     [self.view addSubview:button];
    102     
    103     //跳转
    104     [button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
    105     
    106 }
    107 
    108 - (void)back:(id)sender
    109 {
    110     [self dismissViewControllerAnimated:YES completion:nil];
    111 }
    112 
    113 - (void)didReceiveMemoryWarning {
    114     [super didReceiveMemoryWarning];
    115     // Dispose of any resources that can be recreated.
    116 }
    117 
    118 /*
    119 #pragma mark - Navigation
    120 
    121 // In a storyboard-based application, you will often want to do a little preparation before navigation
    122 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    123     // Get the new view controller using [segue destinationViewController].
    124     // Pass the selected object to the new view controller.
    125 }
    126 */
    127 
    128 @end
    129 
    130 
    131 #ifndef GlobalDefine_h
    132 #define GlobalDefine_h
    133 
    134 #define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
    135 #define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
    136 
    137 #endif /* GlobalDefine_h */
  • 相关阅读:
    python IDLE 如何实现清屏
    协同过滤算法(天池竞赛试题)
    二次排序
    异常类面试题
    异常类
    2020年Java程序员应该学习的10大技术
    java-servlet-EL表达式和java标签
    java-servlet过滤器和监听
    java-Servlet-cookie and session
    java-servlet-转发AND路径
  • 原文地址:https://www.cnblogs.com/songlei0601/p/5769286.html
Copyright © 2011-2022 走看看