iOS UIButton各类属性设置大全

基本属性

  • 设置自定义的按钮
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
  • 设置一个圆角的按钮
UIButton *button1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
  • 按钮的位置坐标
button1.frame=CGRectMake(80,250,250, 30);
  • 普通状态按钮标题
[button1 setTitle:@"Button1" forState:UIControlStateNormal];
  • 高亮状态的按钮标题
[button1 setTitle:@"高亮状态" forState:UIControlStateHighlighted];//
  • 高亮状态光晕效果
[button1 setShowsTouchWhenHighlighted:YES];
  • 设置标题的颜色
[button1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  • 设置标题的字体大小
[button1.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];

或者

 button1.titleLabel.font = [UIFont systemFontOfSize:16];
  • 设置背景颜色
[button1 setBackgroundColor:[UIColor blueColor]];
  • 图片被拉伸式地设置背景图片
[button1 setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
  • 图片保持原来大小地设置背景图片
[button1 setImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
[[button1 titleLabel]setShadowColor:[UIColor blackColor]];
[[button1 titleLabel]setShadowOffset:CGSizeMake(-0.5, -0.5)];
button1.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
[self.view addSubview:button1];

监听事件


[button1 addTarget:self action:@selector(Click_Button) forControlEvents:UIControlEventTouchUpInside];
}
-(void)Click_Button
{
NSLog(@"已点击...");

}

未完,待续更新………

你可能感兴趣的:(UIButton)