iOS UIButton各类属性设置大全

来源:互联网 发布:阿里云切换系统 编辑:程序博客网 时间:2024/05/01 22:46
   //设置自定义的按钮
   //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(@"已点击...");


}
未完,待续更新.........
1 0
原创粉丝点击