1 UIButton *bt = [UIButton buttonWithType:UIButtonTypeContactAdd];// UIButtonTypeCustom, UIButtonTypeRoundedRect; // 2 [bt setTitle:@"myButton" forState:UIControlStateNormal]; // 普通状态 3 [bt setTitle:@"Button1" forState:UIControlStateHighlighted]; // 触摸时 4 [bt setTitle:@"disButton" forState:UIControlStateDisabled]; // 无效时 5 [bt setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; // 普通状态下的字体颜色 6 7 bt.titleLabel.font = [UIFont boldSystemFontOfSize:24]; // 按钮字体 8 bt.titleLabel.shadowOffset = CGSizeMake(1, 1); 9 bt.titleLabel.shadowColor = [UIColor redColor]; 10 11 12 [bt setImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal]; 13 // 普通状态下图片,只在UIButtonTypeCustom,UIButtonTypeRoundedRect下有效 14 [bt setBackgroundImage:[UIImage imageNamed:@"background.png"] forState:UIControlStateNormal]; // 设置背景图 15 16 UIEdgeInsets insets; // 设置按钮内部图片间距 17 insets.top = insets.bottom = insets.right = insets.left = 10; 18 bt.contentEdgeInsets = insets; 19 20 bt.titleEdgeInsets = insets; // 标题间距 21 22 [bt addTarget:self 23 action:@selector(click:) 24 forControlEvents:UIControlEventTouchUpInside]; // 添加事件响应