Ios 自定义导航栏错误

Ios 自定义导航栏错误,ios,xcode,uinavigationbar,Ios,Xcode,Uinavigationbar,我正在尝试在iOS 7中定制导航栏。我创建的自定义类是UINavigationBar的子类。在这里,我做了以下更改: - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setBarTintColor:[UIColor blackColor]]; [self setTranslucent:YES];

我正在尝试在iOS 7中定制导航栏。我创建的自定义类是UINavigationBar的子类。在这里,我做了以下更改:

- (instancetype)initWithFrame:(CGRect)frame {
     self = [super initWithFrame:frame];
    if (self) {
        [self setBarTintColor:[UIColor blackColor]];
        [self setTranslucent:YES];
        [self setAlpha:0.6f];
    }
return self;
}

并且没有任何更改,我在interface builder中设置了自定义类。我应该怎么做?

如果您使用脚本创建UINavigationBar,请尝试使用Coder覆盖initWithFrame,而不是initWithFrame。
在这种情况下,尝试将断点设置为method并检查它。如果您在IB中使用自定义视图,则至少会调用此方法,您还应该覆盖awakeFromNib,并在那里执行一些初始化。在您的代码中,它可以是:

- (instancetype)initWithFrame:(CGRect)frame {
     self = [super initWithFrame:frame];
     if (self) {
        [self setup];
    }
    return self;
}

-(void)awakeFromNib {
    [self setup];
}

-(void)setup {
     [self setBarTintColor:[UIColor blackColor]];
     [self setTranslucent:YES];
     [self setAlpha:0.6f];
}