IOSインタフェース開発のUIView

7990 ワード

前に勉強したObjective-CやSwiftはいくつかの文法で、本当のIOS開発とは違います.それらの関係はJavaやAndroidと同じで、JavaがAndroidを開発するとは限りません.ここでObjective-CやSwiftを使うと必ずしもIOSを開発するとは限りません.IOSは多くの枠組みを学ぶ必要があります.
Foundationの他のフレームワークは、このフレームワークの上に構築され、いくつかのデータ操作クラスを提供します.
UIKEtは、タッチ関係者ベースのクラスを作成します.
Core Data管理アプリケーションデータモデル
Core Graphicsグラフィック処理フレームワーク
Core Animationアニメーションと仮想効果フレームワーク
OpenGL ESは2 Dと3 D描画ツールを提供する
次にUImitフレームワークのいくつかのクラスの使用について学習し、最も基礎的なクラスから、UIViewは多くのコントロールクラスの親であるが、すべてのコントロールクラスの親ではないことを理解しなければならない.
次のコードでは、UIDIewのいくつかのプロパティを使用し、UIBUuttonを介して別のインタフェースを起動します.
//
//  ViewController.m
//  UIViewDemo
//
//  Created by dcr on 2016/12/12.
//  Copyright © 2016  All rights reserved.
//

#import "ViewController.h"
#import "ImageViewController.h"
#import "LabelViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //      
    CGRect rect = [[UIApplication sharedApplication] statusBarFrame];
    //    
    float width = [[UIScreen mainScreen] bounds].size.width;
    float height = [[UIScreen mainScreen] bounds].size.height;
    NSLog(@"width = %f height = %f 
status bar w = %f h = %f", width, height, rect.size.width, rect.size.height); // //CGRect rectNav = self.navigationController.navigationBar.frame; //NSLog(@"rectNav w = %f h = %f", rectNav.size.width, rectNav.size.height); UIView *view1 = [[UIView alloc] init]; view1.frame = CGRectMake(10, rect.size.height + 10, width - 20, height - rect.size.height - 20); NSLog(@"frame x = %f y = %f w = %f h = %f", view1.frame.origin.x, view1.frame.origin.y, view1.frame.size.width, view1.frame.size.height); //bounds , x y 0 NSLog(@"bounds x = %f y = %f w = %f h = %f", view1.bounds.origin.x, view1.bounds.origin.y, view1.bounds.size.width, view1.bounds.size.height); NSLog(@"center x = %f y = %f", view1.center.x, view1.center.y); view1.backgroundColor = [UIColor redColor]; [self.view addSubview:view1]; // UIView *superView = view1.superview; superView.backgroundColor = [UIColor greenColor]; UIView *view2 = [[UIView alloc] init]; view2.backgroundColor = [UIColor blueColor]; view2.frame = CGRectMake(10, 150, 50, 50); view2.tag = 2; [view1 addSubview:view2]; UIView *view3 = [[UIView alloc] init]; view3.backgroundColor = [UIColor purpleColor]; view3.frame = CGRectMake(20, 130, 30, 100); view3.tag = 3; [view1 addSubview:view3]; // NSArray *subArray = view1.subviews; for(UIView *view in subArray){ if(view.tag == 3) view.backgroundColor = [UIColor whiteColor]; } // Tag UIView *subView = [view1 viewWithTag:2]; subView.backgroundColor = [UIColor greenColor]; // , View //UIView *view4 = [[UIView alloc] init]; //view4.backgroundColor = [UIColor purpleColor]; //view4.frame = CGRectMake(40, 110, 100, 200); //view4.tag = 4; //[self.view addSubview:view4]; // [view1 exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; // UIView *view5 = [[UIView alloc] init]; view5.backgroundColor = [UIColor blackColor]; view5.frame = CGRectMake(45, 110, 30, 100); view5.tag = 5; //[view1 insertSubview:view5 atIndex:1]; [view1 insertSubview:view5 aboveSubview:view2]; //[view1 insertSubview:view5 belowSubview:view2]; // // //[view1 bringSubviewToFront:view5]; // [view1 sendSubviewToBack:view5]; // UIView *centerView = [[UIView alloc] init]; centerView.backgroundColor = [UIColor purpleColor]; centerView.frame = CGRectMake(width/2 - 25, height/2 - 25 - rect.size.height, 50, 50); centerView.autoresizesSubviews = YES; centerView.tag = 1001; [view1 addSubview:centerView]; UIView *topView = [[UIView alloc] init]; topView.backgroundColor = [UIColor redColor]; topView.frame = CGRectMake(10, 10, 30, 30); topView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin| UIViewAutoresizingFlexibleBottomMargin| UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight; [centerView addSubview:topView]; UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeSystem]; addBtn.frame = CGRectMake(50, height/2 - rect.size.height + 75, 100, 40); addBtn.backgroundColor = [UIColor whiteColor]; addBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [addBtn setTitle:@" " forState:UIControlStateNormal]; [addBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [addBtn addTarget:self action:@selector(addClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:addBtn]; UIButton *sbuBtn = [UIButton buttonWithType:UIButtonTypeSystem]; sbuBtn.frame = CGRectMake(200, height/2 - rect.size.height + 75, 100, 40); sbuBtn.backgroundColor = [UIColor whiteColor]; sbuBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [sbuBtn setTitle:@" " forState:UIControlStateNormal]; [sbuBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [sbuBtn addTarget:self action:@selector(subClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:sbuBtn]; // UILabel UIButton *btnLabel = [UIButton buttonWithType:UIButtonTypeSystem]; btnLabel.frame = CGRectMake(50, height/2 - rect.size.height + 130, 100, 40); btnLabel.backgroundColor = [UIColor whiteColor]; btnLabel.titleLabel.font = [UIFont systemFontOfSize:16]; [btnLabel setTitle:@" UILabel" forState:UIControlStateNormal]; [btnLabel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [btnLabel addTarget:self action:@selector(btnLabelClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnLabel]; // UIImageView UIButton *btnImageView = [UIButton buttonWithType:UIButtonTypeSystem]; btnImageView.frame = CGRectMake(50, height/2 - rect.size.height + 190, 200, 40); btnImageView.backgroundColor = [UIColor whiteColor]; btnImageView.titleLabel.font = [UIFont systemFontOfSize:16]; [btnImageView setTitle:@" UIImageView" forState:UIControlStateNormal]; [btnImageView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [btnImageView addTarget:self action:@selector(btnImageViewClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btnImageView]; } /** */ - (void)addClick{ UIView *view = [self.view viewWithTag:1001]; view.frame = CGRectMake(view.frame.origin.x-5, view.frame.origin.y-5, view.frame.size.width+10, view.frame.size.height+10); } /** */ - (void)subClick{ UIView *view = [self.view viewWithTag:1001]; view.frame = CGRectMake(view.frame.origin.x+5, view.frame.origin.y+5, view.frame.size.width-10, view.frame.size.height-10); } /** LabelViewController */ - (void)btnLabelClick{ // [self presentViewController:[[LabelViewController alloc] init] animated:true completion:^{ // NSLog(@"LabelViewController start completion"); }]; } /** ImageViewController */ - (void)btnImageViewClick{ // [self presentViewController:[[ImageViewController alloc] init] animated:true completion:^{ // NSLog(@"ImageViewController start completion"); }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

サンプルコードのダウンロード:http://download.csdn.net/detail/deng0zhaotai/9715127