UIButton

/***********************************************************************************/

#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate


-(void)dealloc

{

    [_window release];

    [super dealloc];

}

- (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 grayColor];

    [self.window makeKeyAndVisible];

    [_window release];

    UIViewController *vc =[[UIViewController alloc] init];

    self.window.rootViewController=vc;

    [vc release];

    

    

//    UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(50, 50,100, 50)];

//    label.backgroundColor =[UIColor yellowColor];

//    [self.window addSubview:label];

//    [label release];

//    label.text =@"程锦乐";    //添加汉字

//    label.textAlignment =1; //居中对齐

//    label.textColor =[UIColor blackColor];  //设置字体颜色

//    label.font=[UIFont systemFontOfSize:20]; //字体大小

//    label.shadowColor =[UIColor greenColor];  //阴影颜色

//    label.shadowOffset = CGSizeMake(5, 5);    //阴影大小

     /// 加边框

//

//    label.layer.borderWidth =1;

     ///加弧度

//    label.layer.cornerRadius =50;

    ///把多余的框(部分)隐藏掉

//    label.layer.masksToBounds =YES;


    /// UIButton

//    UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];

//    button.backgroundColor =[UIColor  orangeColor];

//    [self.window addSubview:button];

//    [button release];

//    /// UIButton提供了通过便利构造器创建的方法

//    UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];

//    ///设置尺寸

//    button.frame =CGRectMake(100, 100, 150, 50);

//    button.backgroundColor =[UIColor redColor];

//    [self.window addSubview:button];

//    ///通过这种方法创建不需要release

//     button.layer.borderWidth =1;     //边框

//    button.layer.cornerRadius = 50;   //弧度

//    /// button设置标题

//    [button setTitle:@"程锦乐" forState:UIControlStateNormal];

//    /// 标题颜色

//    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

//    /// 标题大小

//    button.titleLabel.font =[UIFont systemFontOfSize:25];

//    ///  button 的点击方法

//    [button addTarget:self action:@selector(cilick:) forControlEvents:UIControlEventTouchUpInside ];

//    

    

//    UIButton *button1 =[UIButton buttonWithType:UIButtonTypeSystem];

//    button1.frame =CGRectMake(100,150 , 150, 50);

//    button1.backgroundColor =[UIColor  greenColor];

//    button1.layer.borderWidth =2;

//    button1.layer.cornerRadius = 48;

//    [self.window addSubview:button1];

//    [button1 setTitle:@"大地瓜" forState:UIControlStateNormal];

//    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

//    button1.titleLabel.font =[UIFont systemFontOfSize:25];

//    [button1 addTarget:self action:@selector(cilick:) forControlEvents:UIControlEventTouchUpInside];

    

    

//    UIButton *button1 =[UIButton buttonWithType:UIButtonTypeSystem];

//    button1.frame =CGRectMake(100, 100, 150, 50);

//    button1.backgroundColor =[UIColor orangeColor];

//    button1.layer.borderWidth= 1;    //加边框

//    button1.layer.cornerRadius =25;  //加弧度

//    [self.window addSubview:button1];

    

    ///设置背景图片

       ///第一种方法

//    [button1 setBackgroundImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];

     ///第二种方法   UIButtonTypeSystem   换成   UIButtonTypeCustom

    UIButton *button2 =[UIButton buttonWithType:UIButtonTypeCustom];

    button2.frame=CGRectMake(100, 150, 150, 50);

    [self.window addSubview:button2];

    button2.layer.borderWidth=1;    //加边框

    button2.layer.cornerRadius=25//加弧度

    [button2 setImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];

    [button2 addTarget:self action:@selector(changeImage:) forControlEvents:UIControlEventTouchUpInside];

    

//    [button2 setTitle:@"你好" forState:UIControlStateNormal];

//    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    //custom 是自定义的button,system没什么太大区别,但是在设置图片上有区别,一个是setBackGroudImgaesetImage有区别,在一个就是custom设置标题还需要额外设置标题颜色

    

    

    

    

    

    

    

    return YES;

}


-(void)cilick:(UIButton *)button

//这个参数button就是触发方法对应的那个对象

//    NSLog(@"测试一下");

//    NSLog(@"%@",button.currentTitle);

   //点击button更换标题

    if ([button.currentTitle isEqualToString:@"程锦乐"])

    {

        [button setTitle:@"笑哈哈" forState:UIControlStateNormal];

    }else

    if ([button.currentTitle isEqualToString:@"笑哈哈"])

    {

        [button setTitle:@"程锦乐" forState:UIControlStateNormal];

    }

     

    

}


-(void)changeImage:(UIButton *)button

{

    NSLog(@"%d",button.selected);

    if (button.selected == NO)

    {

        [button setImage:[UIImage imageNamed:@"BtnOn.png"] forState:UIControlStateNormal];

    }else

        {

            [button setImage:[UIImage imageNamed:@"BtnOff.png"] forState:UIControlStateNormal];

        }

    button.selected = !button.selected;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值