iOS UIBarButtonItem 仅在第一次按下后改变

iOS UIBarButtonItem only change after first press

我在使用简单的 UIBarButton 并将其命名为 "Send" 并使用 Storyboard

命名为白色时遇到问题

在 viewdidload 中,我使用此代码将色调颜色更改为红色,但它保持为白色,只有在我按下它 1 次后才变为红色,而且它变得有点小@-@,无法弄清楚这里的问题是什么,我之前没有任何代码可以更改按钮

- (void)viewDidLoad
{
    [super viewDidLoad];
    [_sendEPinButton setTintColor:[UIColor redColor]];

    center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(keyboardOnScreen:) name:UIKeyboardWillShowNotification object:nil];
    [center addObserver:self selector:@selector(keyboardOffScreen:) name:UIKeyboardWillHideNotification object:nil];

    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
    CTCarrier *carrier = [networkInfo subscriberCellularProvider];

    if (carrier.isoCountryCode.length == 0) {
        self.geocoder = [[CLGeocoder alloc] init];

        self.locationManager = [[CLLocationManager alloc] init];

        if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
            [self.locationManager requestAlwaysAuthorization];
        }

        self.locationManager.delegate = self;
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [self.locationManager startMonitoringSignificantLocationChanges];
//        [self.locationManager startUpdatingLocation];
    } else {
        countryCodeString = carrier.isoCountryCode;
    }
    _contactTextfield.delegate = self;

    [_contactTextfield setTintColor:colorFromRGB(67, 160, 48)];
}

在.h文件中

@property (strong, nonatomic) IBOutlet UIBarButtonItem *sendEPinButton;

按下前

按下后

你应该在 viewdidload 或者你创建 UIBarButtonItem 的地方写这些行..

[_sendEPinButton setTintColor:[UIColor redColor]];

请将代码放在 ViewDidAppear 方法中查看。有时 outlets 在 vi​​ew did load 方法中无法正确加载。