delegate

导航

 

//系统默认UIButtonTypeSystem

UIButton*btn1=[UIButton buttonWithType:UIButtonTypeSystem];

//设置按钮的坐标和大小

btn1.frame=CGRectMake(0,20,320,30);

//设置按钮的背景颜色

btn1.backgroundColor=[UIColor redColor];

//设置按钮中文本信息

[btn1 setTitle:@"按钮" forState:UIControlStateNormal];

//当按钮处于按下状态时,称为高亮状态

[btn1 setTitlt:@"点击" forState:UIControlStateHighlighted];

 //tag

    btn1.tag=100;

    //给按钮添加点击事件

    [btn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

    [self.window addSubview:btn1];

//设置圆角

    btn4.layer.masksToBounds=YES;

    btn4.layer.cornerRadius=10;

 //修改按钮中文本颜色

    [btn5 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

//    //修改前景的颜色

//    [btn5 setTintColor:[UIColor redColor]];

    [self.window addSubview:btn5];

    

    

    //按钮自定义样式

    UIButton *btn6=[UIButton buttonWithType:UIButtonTypeCustom];

    btn6.frame=CGRectMake(0, 220, 320, 30);

 

    //获得图片对象

    //imageNamed加载的图片一般为几K到几十K

    //UIImage *image=[UIImage imageNamed:@"player1.png"];

   

    //第二种获得图片的方式

   //查找工程下指定文件的路径

    NSString *strPath=[[NSBundle mainBundle]pathForResource:@"player1" ofType:@"png"];

    //根据指定路径下的内容初始化图片对象

    UIImage *image=[UIImage imageWithContentsOfFile:strPath];

   

    [btn6 setImage:image forState:UIControlStateNormal];

    [self.window addSubview:btn6];

posted on 2015-04-10 09:09  jsonUserList  阅读(68)  评论(0)    收藏  举报