IOS开发之纯代码界面----基本控件使用篇1

纯代码实现的优缺点:

优点:可以灵活地适应各种环境,无论是什么ios版本,或者iPhone,ipad,都可以动态地适应各种场景。

缺点:代码量大,构建控件麻烦,点击的监听函数和delegate要自己手动创建


第一课:在程序中添加 UIWindow。UIWindow也是UIView的子类,这个是我们的程序窗口,我们一个程序的最基本承载界面(其他的界面都是添加到这个窗口上的)。

这个Demo我们主要学习UIWindow

首先我们要了解在iOS上我们看到的大部分应用都是单窗口应用,也就是一个应用只有一个Window,且占满整个屏幕。

我们建立了一个Empty Application,然后我们修改他的AppDelegate.m文件中的下列函数

- (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];

    return YES;

}

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //*******************************************************************************
    //上面这句是创建一个UIWindow实例,Frame为“[[UIScreen mainScreen] bounds]”的返回 CGRect
    //在这里我们可以用 CGRectMake(0, 0, 100, 100) 自己重新定制UIWindow 的 Frame
    //self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    //*******************************************************************************

    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    //*******************************************************************************
    //上面这句是修改self.window 这个实例的 backgroundColor 属性,
    //我们可以把它改成红色
    //self.window.backgroundColor = [UIColor redColor];
    //或者使用RBG颜色 r g b 取值区间为 0~1
    //self.window.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
    //或者使用图片
    //UIImage *backImage = [UIImage imageNamed:@"background"];
    //self.window.backgroundColor = [UIColor colorWithPatternImage:backImage];
    //*******************************************************************************
    
    //*******************************************************************************
    //另外 按住command 鼠标点击 UIWindow 可以看到,UIWindow是继承自UIView,也就是说你看到的UIWindow本质也是一个UIView
    //所以,UIWindow有UIView的一切属性,可以自己修改看看效果
    //*******************************************************************************
    
    //*******************************************************************************
    //本Demo结束,以后如果有类之间的跳转,我会给出跳转提示
    //*******************************************************************************
    
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end









  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值