【小编推荐】ios 代码添加控件

2015-01-15   |   发布者:梁国芳   |   查看:3320次

ios
 

#import "AppDelegate.h"

 

@interface AppDelegate ()

 

@end

 

@implementation AppDelegate

 

 

- (void)dealloc{

 

    [_window release];

    [super   dealloc];

}

 

CGRect rect;

 

CGSize size ;

CGFloat width;

CGFloat height;

UIColor * liangColor;

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

    // Override point for customization after application launch.

    

    

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

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor  redColor];

    [self.window makeKeyAndVisible];

    

    

    

    

   rect = [[UIScreen mainScreen] bounds];

    size = rect.size;

    width = size.width;

    height = size.height;

    

    liangColor = [UIColor colorWithRed:20/255.0 green:240/255.0 blue:240/255.0 alpha:1];

 

 

    

    

    

    

    NSLog(@"屏幕的宽度是%f,屏幕的高度是%f",width,height);

    UIButton* button2 =[[UIButton   alloc]init];

    

    button2.frame=CGRectMake((width-100)/2,height-100,100,50);

    

    button2.backgroundColor =   liangColor;

    

    [button2 setTitle:@"提交"forState:UIControlStateNormal];

    

    [button2 setTitleColor:[UIColor  purpleColor]forState:UIControlStateNormal];

    [self.window  addSubview:button2];

    

    

 

    return YES;

}