码迷,mamicode.com
首页 > 其他好文 > 详细

草稿-九宫格

时间:2015-08-25 21:26:34      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

#import "AppDelegate.h"

 

@interface AppDelegate ()

@property(nonatomic,strong)NSArray*app;

 

 

@end

 

@implementation AppDelegate

-(NSArray *)app{

    if (_app == nil) {

        NSString*path=[[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil];

        _app=[NSArray arrayWithContentsOfFile:path];

    }

    return _app;

 

}

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    

    int totalloc=4;

        CGFloat appvieww=90;

        CGFloat appviewh=90;

        CGFloat margin=(self.window.frame.size.width-totalloc*appvieww)/(totalloc+1);

        for (int i=0; i<self.app.count; i++) {

            NSLog(@"====");

                int row=i/totalloc;//行号

                int loc=i%totalloc;//列号

                CGFloat appviewx=margin+(margin+appvieww)*loc;

                CGFloat appviewy=margin+(margin+appviewh)*row;

                 //创建uiview控件

                 UIView *appview=[[UIView alloc]initWithFrame:CGRectMake(appviewx, appviewy, appvieww, appviewh)];

                 [appview setBackgroundColor:[UIColor brownColor]];

                 [self.window addSubview:appview];

            

            //创建文本

            UIButton*appbutton=[UIButton buttonWithType:UIButtonTypeSystem];

            appbutton.frame=CGRectMake(0, 50, 80, 20);

 

            [appbutton setTitle:self.app[i] forState:UIControlStateNormal];

            [appbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];

   

            

            [appview addSubview:appbutton];

            

        }

 

    

    

    return YES;

}

草稿-九宫格

标签:

原文地址:http://www.cnblogs.com/sunbinboke/p/4758547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!