iOS UIBarButtonItem仅在首次按下后更改

时间:2015-09-07 11:38:46

标签: objective-c uinavigationbar uibarbuttonitem

我有问题,我只使用一个简单的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;

在按下之前 enter image description here

按下之后 enter image description here

2 个答案:

答案 0 :(得分:1)

请将代码放在ViewDidAppear方法中查看。有时出口装载方法无法正确装载。

答案 1 :(得分:0)

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

[_sendEPinButton setTintColor:[UIColor redColor]];