2015-09-11 2 views
0
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

я не в состоянии го цвета для кнопки всегда показывает синий цвет, логотип цвет ... Что проблема быстро .. –

+0

Где вы установили textColor кнопки? –

ответ

1
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: для государства:]

для этого.

[ConnexionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
0

Пожалуйста, удалите

UIButton *ConnexionButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

Добавить

UIButton *ConnexionButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[ConnexionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[ConnexionButton setTitleColor:[UIColor colorWithRed:150.0/256.0 green:150.0/256.0 blue:150.0/256.0 alpha:1.0] forState:UIControlStateHighlighted]; 
+0

Спасибо и вам .... работает довольно хорошо ..... –

+0

Если это полезно для вас, пожалуйста, повысьте и отметьте. – user3182143

Смежные вопросы