UIButton的基本用法,平时用的也就是这么多,其他遇到在加
//实例化2种方法
UIButton *btn1 = [[UIButton alloc] init];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//坐标和大小
btn.frame = CGRectMake(100, 100, 100, 100);
//背景颜色
btn.backgroundColor = [UIColor redColor];
//设置字体
[btn setTitle:@"UIButton" forState:UIControlStateNormal];
//设置字体颜色
[btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//设置层的弧度
btn.layer.cornerRadius = 50.0f;
//多余的层是否隐藏
btn.layer.masksToBounds = YES;
//设置层的宽度
btn.layer.borderWidth = 1.0f;
//设置层的颜色
btn.layer.borderColor = [[UIColor yellowColor]CGColor];
//标记
btn.titleLabel.tag = 100;
//设置文字的大小
btn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
//文字加粗
btn.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//设置图片
[btn setImage:[UIImage p_w_picpathNamed:@"1.png"] forState:UIControlStateNormal];
//设置背景图片
[btn setBackgroundImage:[UIImage p_w_picpathNamed:@"1.png"] forState:UIControlStateNormal];
//设置透明度
[btn setAlpha:0.5f];
//是否选择
[btn setSelected:YES];
//是否隐藏
[btn setHidden:NO];
//是否高亮
[btn setHighlighted:YES];
//是否可以触摸
[btn setEnabled:YES];
//设置是否交互事
[btn setUserInteractionEnabled:YES];
//设置文字的偏移
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
//设置图片的偏移
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
//垂直
[btn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
//水平
[btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
//文字居中
btn.titleLabel.textAlignment = NSTextAlignmentCenter;
//设置中心坐标
[btn setCenter:CGPointMake(100, 100)];
//设置文字阴影颜色
[btn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
//文字发光
[btn setShowsTouchWhenHighlighted:YES];
//点击事件
[btn addTarget:self action:@selector(goToView:) forControlEvents:UIControlEventTouchUpInside];
//加入视图中
[self.view addSubview:btn];