2011-03-16 116 views
0

请问我刚刚添加了一个UIToolbar到我的视图后退按钮,我想在这个UIToolbar中添加一个标题,在界面生成器中我不能手动完成,所以我应该在程序中添加它,我应该如何请做我的视图类是这样的:如何为我的UIToolbar添加标题?

#import "AproposView.h" 


@implementation AproposView 

-(IBAction)backMainView{ 


    [self dismissModalViewControllerAnimated:YES]; 

} 

这回按钮处于UItoolbar,所以我 只需要添加标题,THX提前:)

+0

您是否尝试过接口生成器? – ThomasRS 2011-03-16 15:17:04

回答

1
#define UIColorFromRGB(rgbValue) [UIColor \ 
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ 
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \ 
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]  

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 202, 23)]; 
label.textAlignment = UITextAlignmentCenter; 
label.backgroundColor = [UIColor clearColor]; 
label.shadowColor = UIColorFromRGB(0xe5e7eb); 
// label.shadowOffset = CGSizeMake(0, 1); 
    label.textColor = UIColorFromRGB(0x717880); 
    label.text = @"Edit Classes"; 
    label.font = [UIFont boldSystemFontOfSize:20.0]; 
    label.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; 
    label.shadowOffset = CGSizeMake(0, -1.0); 
    UIBarButtonItem *toolBarTitle = [[UIBarButtonItem alloc] initWithCustomView:label]; 
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; 
toolBar.items = [NSArray arrayWithObjects:fixedSpace, toolBarTitle, fixedSpace, nil]; 
+0

THX为您的答案,但我应该在哪里把这个? – Malloc 2011-03-16 14:01:19

+0

in'viewDidLoad'你想要什么样的课程 – Andrew 2011-03-20 20:55:57

+0

如果这个答案有帮助,你会介意检查它旁边的绿色箭头吗? – Andrew 2011-11-23 07:20:56

0

而是加入一个UILabel到UIToolbar添加一个UITextField作为一个Bar Button Item并设置所需的标题并禁用它的UserInteraction。 真的很简单和容易的技术。 Sanpshot Interface Builder

相关问题