UIButton *ConnexionButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[ConnexionButton setTitle:@"" forState:(UIControlState)UIControlStateNormal];
[ConnexionButton addTarget:self action:@selector(ConnexionAction) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
UIImage *NewImage = [UIImage imageNamed:@"connectionbtnIcon"];
[ConnexionButton setBackgroundImage:NewImage forState:UIControlStateNormal];
[ConnexionButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[TopView addSubview:ConnexionButton];
[ConnexionButton setTitle:NSLocalizedString(@"Connexion", @"") forState:UIControlStateNormal];
[ConnexionButton.titleLabel setFont:PANTON_SEMIBOLD(15)];
[ConnexionButton.titleLabel setTextColor:[UIColor whiteColor]];
[TopView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[ConnexionButton]-20-|" options:0 metrics:nil views:views]];
[TopView addConstraint:[NSLayoutConstraint constraintWithItem:ConnexionButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:TopView attribute:NSLayoutAttributeTop multiplier:1.0 constant:90]];
NSLayoutConstraint *ConnexionButtonHeightConstraint = [NSLayoutConstraint constraintWithItem:ConnexionButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:35.0];
[TopView addConstraint:ConnexionButtonHeightConstraint]
最佳答案
UIButton *ConnexionButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
替换这一行....
UIButton *ConnexionButton = [UIButton buttonWithType:UIButtonTypeCustom];
ConnexionButton.frame = CGRectMake(x, y, w, h);
[ConnexionButton setTitle:@""
forState:(UIControlState)UIControlStateNormal];
[ConnexionButton addTarget:self
action:@selector(ConnexionAction)
forControlEvents:(UIControlEvents)UIControlEventTouchDown];
UIImage *NewImage = [UIImage imageNamed:@"connectionbtnIcon"];
[ConnexionButton setBackgroundImage:NewImage forState:UIControlStateNormal];
[ConnexionButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[TopView addSubview:ConnexionButton];
[ConnexionButton setTitle:NSLocalizedString(@"Connexion", @"") forState:UIControlStateNormal];
[ConnexionButton.titleLabel setFont:PANTON_SEMIBOLD(15)];
[ConnexionButton.titleLabel setTextColor:[UIColor whiteColor]];
[TopView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[ConnexionButton]-20-|" options:0 metrics:nil views:views]];
[TopView addConstraint:[NSLayoutConstraint constraintWithItem:ConnexionButton attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:TopView attribute:NSLayoutAttributeTop multiplier:1.0 constant:90]]; NSLayoutConstraint *ConnexionButtonHeightConstraint = [NSLayoutConstraint constraintWithItem:ConnexionButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:35.0];
[TopView addConstraint:ConnexionButtonHeightConstraint];
设置颜色... 你可以使用
-[UIButton setTitleColor:forState:]
这样做。
[ConnexionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
关于ios - 在 iOS 中设置按钮文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32519284/