当前位置:首页 > 操作系统 > Ios

IOS--纯代码方式编写View

AppDelegate:

             1
            #import
            "
            AppDelegate.h
            "
             2
            #import
            "
            TestController.h
            "
             3
             4
            @interface
             AppDelegate ()

             5 @property(nonatomic,strong)TestController *controller;
 6@end 7 8@implementation AppDelegate
 91011 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
12// Override point for customization after application launch.13     self.window = [[UIWindow alloc]init];
1415     self.controller = [[TestController alloc]init];
1617     self.window.rootViewController = self.controller;
1819    [self.window makeKeyAndVisible];
20return YES;
21 }

TestController:

             1
            #import
            "
            TestController.h
            "
             2
            #import
            "
            RootView.h
            "
             3
             4
            @interface
             TestController()

             5
             6 @property(nonatomic,strong)RootView *rootView;
 7 8@end 910@implementation TestController
1112 - (void)viewDidLoad
13{
14    [super viewDidLoad];
1516     self.rootView = [[RootView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
17     self.view = self.rootView;
18}
1920@end

RootView 继承 UIView

             1
            #import
            "
            RootView.h
            "
             2
             3
            @interface
             RootView()

             4
             5
            @end
             6
             7
            @implementation
             RootView

             8
             9 -(instancetype)initWithFrame:(CGRect)frame
10{
11     self = [super initWithFrame:frame];
12if (self) {
13         self.backgroundColor = [UIColor blueColor];
14    }
15return self;
16}
1718@end

 

原文:http://www.cnblogs.com/yuge790615/p/5219898.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!