常用的属性

UIButtonType

  • UIButtonTypeCustom
  • UIButtonTypeRounedRect 一个圆角矩形样式的按钮
  • UIButtonTypeDetailDisclosure 一个详细纰漏按钮
  • UIButtonTypeInfoLight 一个信息按钮,有一个浅色背景
  • UIButtonTypeInfoDark 一个信息按钮,有一个黑暗的背景
  • UIButtonTypeContactAdd 一个联系人添加按钮

按下按钮后出发一个事件

在这里插入图片描述

-(void)testUIButton1{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setTitle:@"危险!请勿触摸!" forState:UIControlStateNormal];
    [button sizeToFit];
    [button addTarget:self action:@selector(buttonDidPush) forControlEvents:UIControlEventTouchUpInside];
    button.center = self.view.center;
    button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
        UIViewAutoresizingFlexibleRightMargin |
        UIViewAutoresizingFlexibleTopMargin |
        UIViewAutoresizingFlexibleBottomMargin;
    [self.view addSubview:button];
}

在屏幕中显示不同的按钮

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐