UINavigationController中的setAlpha

时间:2010-08-31 18:21:41

标签: objective-c uinavigationcontroller alpha

我想在我的UINavigationController中设置titleView的alpha。以下是此类的代码:

#import "FAQNavigationController.h"


@implementation FAQNavigationController

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {

    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

 self.navigationItem.titleView.alpha = 0.5;


    [super viewDidLoad];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end

此外,这是该结果的屏幕截图:您可以看到alpha没有改变。

alt text

有什么想法吗?我把它放在错误的地方吗?

1 个答案:

答案 0 :(得分:1)

问题是self.navigationItem.titleView没有给你任何东西。您可以设置该属性以替换屏幕截图中显示的默认标签。但是,没有专门用于实现您想要的API。

问题是:你想要达到什么目标?如果您愿意,可以使条形透明,或者改变它的色调。更改文本不透明度并不容易。你可以摆弄控制器的UINavigationBar的子视图,但我不会这样做。