- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem] ; button.frame = CGRectMake(60,100,200,200) ; [button setTitle:@"button" forState:UIControlStateNormal]; button.backgroundColor = [UIColor redColor]; //[button setBackgroundImage:[UIImage imageNamed:@"灯泡.jpg"] forState:UIControlStateNormal]; //[button setImage:[[UIImage imageNamed:@"灯泡.jpg"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; //button.contentEdgeInsets = UIEdgeInsetsMake(20, 0, 0, 0); //上左下右 //button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 40, 0); //button.titleEdgeInsets = UIEdgeInsetsMake(30, 0, 0, 0); // button.adjustsImageWhenHighlighted = YES; button.showsTouchWhenHighlighted = YES; button.tintColor = [UIColor purpleColor]; button.titleLabel.font = [UIFont boldSystemFontOfSize:30]; [self.view addSubview:button]; button.layer.masksToBounds = YES; button.layer.cornerRadius = 30; [button addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside]; //button.enabled = NO; } - (void)clickBtn:(UIButton *)btn{ [btn setBackgroundColor:[UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:arc4random()%255/255.0]]; [self.view setBackgroundColor:[UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:arc4random()%255/255.0]]; NSLog(@"%@",btn); }
UIButton
猜你喜欢
转载自chenggi102.iteye.com/blog/2307644
今日推荐
周排行