2013-08-20 38 views
0

我的工具栏中有一个barbutton,我试图增加工具栏的高度以及barbutton。我能够使用以下代码增加工具栏的大小。但我仍然无法增加Barbutton内部的高度。有任何想法吗?UIToolbar内部的调整大小按钮

Declaration in .h 

    @property (weak, nonatomic) IBOutlet UIToolbar *viewLogToolbar; 

Code in .m 

    CGRect frameBar = viewLogToolbar.frame; 
    frameBar.size.height = 75; 
    viewLogToolbar.frame=frameBar; 

这不仅增加了UIToolbar的大小,但对于barbutton类似代码不工作。我UIBarButton属性和动作的

声明

@property (weak, nonatomic) IBOutlet UIBarButtonItem *viewLogOut; 

- (IBAction)viewLog:(id)sender; 

回答

1

对于increaing的UIBarButtonItem大小分配的UIButton其customView属性如下:

UIButton *yourbutton = [UIButton buttonWithType:UIButtonTypeCustom]; 
yourbutton.frame = CGRectMake(0, 0, width, height); 
[yourbutton addTarget:self action:@selector(YOUR_METHOD:) forControlEvents:UIControlEventTouchUpInside]; 

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:yourbutton]; 

编辑:您可以通过工具栏栏按钮它:

NSArray *items = [NSArray arrayWithObjects: barButtonItem,nil]; 

[YOUR_TOOLBAR setItems:items animated:NO]; 

希望它可以帮助你。

+0

我已经有一个属性和行动定义为我的UIbarbutton里面UIToolbar像@property(弱,非原子)IBOutlet UIBarButtonItem * viewLogOut; - (IBAction)viewLog:(id)sender;我应该如何使用这段代码? – Gamerlegend

+0

您可以为UIButton事件添加该方法,然后将此UIButton分配给UIBarButtonItem。它会正常工作。 –

+0

@Gamerlegend检查我编辑的调用方法的答案。 –

0
NSMutableArray *buttons=[[NSMutableArray alloc] initWithCapacity:3]; 

    UIButton *reportBtn = [UIButton buttonWithType: UIButtonTypeCustom]; 
    // [reportBtn addTarget:self action:@selector(btnReportClicked) forControlEvents:UIControlEventTouchUpInside]; 
    reportBtn.frame = CGRectMake(330.00, 300.0, 90.0, 30.0); 
    [reportBtn setTitle:@"Report" forState:UIControlStateNormal]; 
    [reportBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
    reportBtn.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:13.0]; 
    //reportBtn.backgroundColor = [UIColor colorWithRed:65.0/255.0 green:105.0/255.0 blue:225.0/255.0 alpha:1.0]; 

    [reportBtn setBackgroundImage:[UIImage imageNamed:@"toolbarbtn.png"] forState:UIControlStateNormal]; 
    [self.view addSubview:reportBtn]; 

    UIBarButtonItem *repoBarbtn =[[UIBarButtonItem alloc]initWithCustomView:reportBtn]; 
    repoBarbtn.style = UIBarButtonItemStyleBordered; 
    [buttons addObject:repoBarbtn]; 
    [repoBarbtn release]; 

试试这个代码一次......可能这将有助于you..put这段代码在viewDidLoad中或其他一些方法。

+0

我不想要一个自定义按钮,我想增加我的按钮在UIToolbar内的大小。我已经有一个属性和动作定义为我的按钮里面的UIToolbar像@property(弱,非原子)IBOutlet UIBarButtonItem * viewLogOut; - (IBAction)viewLog:(id)sender;框架或CGRect选项不与两者中的任何一个来。 – Gamerlegend

+0

然后尝试Nishant的答案.. – Hari1251