UIButton的基本使用

//初始化

 UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];

//设置frame

    button.frame = CGRectMake(40, 250, 60, 40);

//设置指定状态下得标题

    [button setTitle:@"登陆" forState:UIControlStateNormal];

//获取指定状态下的标题

    NSString *normaTitle = [logButton titleForState:UIControlStateNormal];

// 为按钮添加事件,指定按钮点击之后,执行targetaction方法

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

// 移除按钮的点击事件

    [button removeTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpOutside];

   

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

  UIColor *normalYitleColor = [button titleColorForState:UIControlStateNormal];

//设置字体颜色

   [button setTitleShadowColor:[UIColor redColor] forState:UIControlStateNormal];

 UIColor *normalTitleShadowColor = [button titleColorForState:UIControlStateNormal];

//设置字体

    [button setTitle:@"你好" forState:UIControlStateHighlighted];

    

posted on 2015-11-26 20:15  LJ李杰  阅读(121)  评论(0编辑  收藏  举报

导航