gpt4 book ai didi

ios - 在 iOS 中设置按钮文本的颜色

转载 作者:行者123 更新时间:2023-11-29 01:39:56 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com