button是我们经常用到的控件,我把它的属性罗列一下:
UIButton *Button = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 120, 50)]; NSString *str = @"已认证"; [Button setTitle:[NSString stringWithFormat:@"%@",str] forState:UIControlStateNormal]; [Button setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; [Button setImage:[UIImage imageNamed:@"i_ico_class.png"] forState:UIControlStateNormal]; /* 这样的可以控制边缘插入的位置 可以 让一个按钮的背景里面既有图片也有文字,图片和文字的位置可以随意用此调整 */ // [Button setImageEdgeInsets:str.length>1?UIEdgeInsetsMake(0, 3, 0, 0):UIEdgeInsetsMake(0, 20, 0, -40)];//上、左、下、右 [Button setImageEdgeInsets:UIEdgeInsetsMake(0, 3, 0, 0)];//上、左、下、右 Button.backgroundColor = RGB(87, 205, 66); Button.clipsToBounds = YES;//裁剪 Button.titleLabel.font = [UIFont systemFontOfSize:18];//字体大小 Button.layer.cornerRadius = 25;//圆角半径 Button.layer.shadowOffset = CGSizeMake(3, 5); Button.layer.shadowOpacity = 0.8;//阴影的透明度 Button.layer.shadowColor = RGB(87, 205, 66).CGColor;//阴影的颜色 Button.layer.borderColor = RGBA(255, 255, 255, 0.4).CGColor;//边框的颜色 Button.layer.borderWidth = 4;//边框的宽度 [Button addTarget:self action:@selector(weekChooseAction:) forControlEvents:UIControlEventTouchUpInside];//绑定方法 [self.view addSubview:Button]; //实现方法 -(void)weekChooseAction:(id)sender { [UIView animateWithDuration:2 animations:^{ self.view.backgroundColor = [UIColor redColor]; }]; }