在iOS中为按钮文本设置颜色

时间:2015-09-11 08:47:29

标签: ios objective-c uibutton uicolor

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]

0 个答案:

没有答案