标签:
#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