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 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(@"已点击...");


}
未完,待续更新.........

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。