2010-08-31 67 views
0

我想在我的UINavigationController中设置titleView的alpha值。这里是这个类的代码:UINavigationController中的setAlpha

#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

任何想法?我把这个放在错误的地方吗?

+0

请参阅http://stackoverflow.com/a/26365491/1418457 – onmyway133 2014-10-14 16:17:22

回答

1

问题是,self.navigationItem.titleView不给你任何东西。该属性可以由您设置以替换屏幕截图中显示的默认标签。但是,没有API设计用来做你想做的事情。

问题是:你想达到什么目的?如果你想要或者改变它的色调,你可以使它变成半透明的。改变文字不透明度并不太容易。你可能摆弄控制器的UINavigationBar的子视图,但我不想这样做。

+0

感谢您的回答,我实际上需要更改实际标题标签的不透明度。你有什么想法我可以做到这一点?我试图让设计师高兴:) – 2010-08-31 18:36:33

+0

不要让他高兴,告诉他这太难了。我在这里发布了更详细的讨论和一个可能的解决方案在你的其他问题:http://stackoverflow.com/questions/3610826/subclassing-uinavigationbar-in-xcode – 2010-08-31 18:47:36

+0

这个答案已经过时。请参阅http://stackoverflow.com/a/26365491/1418457 – onmyway133 2014-10-14 16:18:10