2013-01-04 16 views

回答

3

你可以試試下面的代碼。

UILabel *yourLabel = [[UILabel alloc]initWithFrame:CGRectMake(260,6,55,32)]; 
    yourLabel.text = @"Ashu"; 
    [self.navigationController.navigationBar addSubview:yourLabel]; 

請告知,如果它的工作原理..

+0

糾正一個括號後,它可以工作。 –

2

下面是一些示例代碼:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 65.0, 30.0)]; 
label.text = @"Text"; 
barButton = [[UIBarButtonItem alloc] initWithCustomView:label]; 

,那麼只需在設置「barButton」等於右導航項目

1

做到這一點的:

yourButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30) ]; 
    [yourButton addTarget:self action:@selector(yourmethod:) forControlEvents:UIControlEventTouchUpInside]; 

    yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 8, 40, 30)]; 
    yourLabel.text = @"your Text"; 
    yourLabel.backgroundColor = [UIColor clearColor]; 
    yourLabel.textColor = [UIColor whiteColor]; 
    yourLabel.font = [UIFont boldSystemFontOfSize:12.0f]; 
    [yourLabel sizeToFit]; 
    [yourButton addSubview:yourLabel]; 

[yourButton sizeToFit]; 

    yourBarButton = [[UIBarButtonItem alloc] initWithCustomView:yourButton]; 
    self.navigationItem.rightBarButtonItem = yourBarButton; 
相關問題