在UIToolbar中调整大小按钮

时间:2013-08-20 09:43:08

标签: ios cocoa-touch uibarbuttonitem 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的大小,但类似的代码对按钮不起作用。

我的UIBarButton属性和操作的声明

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

- (IBAction)viewLog:(id)sender;

2 个答案:

答案 0 :(得分:1)

为了增加UIBarButtonItem大小,将UI按钮分配给其自定义View属性,如下所示:

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];

希望它对你有所帮助。

答案 1 :(得分: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];

尝试使用此代码......可能会帮助您..在viewdidload或其他方法中输出此代码。