首页 > 其他 > 详细

草稿-九宫格

时间:2015-08-25 21:25:09      阅读:174      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!