iOS - 更改 UIBarButtonItem 的高度

发布于 2024-12-03 08:57:49 字数 233 浏览 1 评论 0原文

UIToolbar 有一个很好的调整大小选项(self.navigationController.toolbar.frame) 我想知道是否有人知道更改 UIBarButtonItem 高度的方法?

我有一个高度为 117 像素的自定义工具栏,到目前为止我还没有找到修改工具栏上按钮的方法。另外,我需要它作为工具栏,因为当我在第一个视图中设置资源时,显示的视图被另一个动画视图(剪切场景样式)覆盖,并且工具栏需要在整个过程中保持在顶部。

UIToolbar has a nice option for resizing (self.navigationController.toolbar.frame) I'm wondering if anyone knows of a way to change the height of a UIBarButtonItem?

I have a custom toolbar with a height of 117 pixels and so far I haven't found a way of modifying the buttons on the toolbar. Also I need it to be a toolbar because the displayed view gets covered with another animated view (cut scene style) while I setup assets in the first view and the toolbar needs to stay on top during all of it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

离线来电— 2024-12-10 08:57:49

实际上我自己也遇到过这个问题,我唯一能想到的就是利用 initWithCustomView 并传入一个带有定义框架的 UIButton 。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

/*
* Insert button styling
*/

button.frame = CGRectMake(0, 0, width, height);

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

否则 UIBarButtonItem 只有一个可以设置的宽度属性,但不幸的是没有高度属性。我用 initWithCustomView 做的另一件漂亮的事情是传递一个带有按钮和其他东西(如活动指示器)的工具栏。希望这有帮助。

I've actually run into this myself and the only thing I could come up with was leveraging initWithCustomView and passing in a UIButton with a defined frame.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

/*
* Insert button styling
*/

button.frame = CGRectMake(0, 0, width, height);

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

Otherwise UIBarButtonItem only has a width property that can be set but unfortunately not a height property. Another nifty thing I've done with initWithCustomView is to pass in a toolbar with a button and other things like activity indicators. Hope this helps.

送你一个梦 2024-12-10 08:57:49

使用您喜欢的框架、图像、目标和选择器等创建一个 UIButton ,然后使用 UIBarButtonIteminitWithCustomView: 方法并将 UIButton 用作自定义视图。

create a UIButton with your preferred frame and image and target and selector and etc. then use UIBarButtonItem's initWithCustomView: method and use the UIButton as the customView.

咿呀咿呀哟 2024-12-10 08:57:49

让这个简单的三个步骤

1 编写属性:

@property (nonatomic, strong) IBOutlet UIToolbar *toolBarActive;
@property (nonatomic, strong) IBOutlet UIButton *uiButton;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *uiButtonItem;

2 综合:

@synthesize toolBarActive = _toolBarActive;
@synthesize uiButton = _uiButton;
@synthesize uiButtonItem = _uiButtonItem;

3 编写实现:

-(UIToolbar *) toolBarActive {
    if( _toolBarActive == nil ) {
        _toolBarActive = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 380, 320, 40)];
        _toolBarActive.tintColor = [UIColor blackColor];  
        NSMutableArray *arrayItem = [[NSMutableArray alloc] init];
        [arrayItem addObject:self.uiButtonItem];
        [_toolBarActive setItems:arrayItem animated:YES];
    }
    return _toolBarActive;
}

- (UIButton *) uiButton {
    if( _uiButton == nil ) {
        _uiButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
        [_uiButton addTarget:self action:@selector(deletePointFromTrip) forControlEvents:UIControlEventTouchUpInside];
        [_uiButton setImage:[UIImage imageNamed:@"editable.png"] forState:UIControlStateNormal];
    }
    return _uiButton;
}

- (UIBarButtonItem *) uiButtonItem {
    if( _uiButtonItem == nil ) {
        _uiButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.uiButton];
        [_uiButtonItem setEnabled:YES];
    }
    return _uiButtonItem;
}

现在,当您在 uibarbuttomitem 上有 uibutton 时,您可以为 uibutton 定义所有属性,例如图像、操作等。

Make this simple three steps

1 Write property:

@property (nonatomic, strong) IBOutlet UIToolbar *toolBarActive;
@property (nonatomic, strong) IBOutlet UIButton *uiButton;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *uiButtonItem;

2 Synthesize:

@synthesize toolBarActive = _toolBarActive;
@synthesize uiButton = _uiButton;
@synthesize uiButtonItem = _uiButtonItem;

3 Write implementation:

-(UIToolbar *) toolBarActive {
    if( _toolBarActive == nil ) {
        _toolBarActive = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 380, 320, 40)];
        _toolBarActive.tintColor = [UIColor blackColor];  
        NSMutableArray *arrayItem = [[NSMutableArray alloc] init];
        [arrayItem addObject:self.uiButtonItem];
        [_toolBarActive setItems:arrayItem animated:YES];
    }
    return _toolBarActive;
}

- (UIButton *) uiButton {
    if( _uiButton == nil ) {
        _uiButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 50, 50)];
        [_uiButton addTarget:self action:@selector(deletePointFromTrip) forControlEvents:UIControlEventTouchUpInside];
        [_uiButton setImage:[UIImage imageNamed:@"editable.png"] forState:UIControlStateNormal];
    }
    return _uiButton;
}

- (UIBarButtonItem *) uiButtonItem {
    if( _uiButtonItem == nil ) {
        _uiButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.uiButton];
        [_uiButtonItem setEnabled:YES];
    }
    return _uiButtonItem;
}

Now when you have uibutton on uibarbuttomitem you can define all property for uibutton like, image, action etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文