UIToolbar有调整(self.navigationController.toolbar.frame)我想知道如果任何人的方式来改变的UIBarButtonItem的高度知道一个不错的选择?iOS版 - 更改的UIBarButtonItem的高度
我有一个自定义工具栏与117个像素的高度,到目前为止,我还没有发现修改工具栏上的按钮的方式。此外,我需要它成为一个工具栏,因为显示的视图被另一个动画视图(剪切场景样式)覆盖,而我在第一个视图中设置资源并且工具栏需要在所有视图中保持最佳状态。
UIToolbar有调整(self.navigationController.toolbar.frame)我想知道如果任何人的方式来改变的UIBarButtonItem的高度知道一个不错的选择?iOS版 - 更改的UIBarButtonItem的高度
我有一个自定义工具栏与117个像素的高度,到目前为止,我还没有发现修改工具栏上的按钮的方式。此外,我需要它成为一个工具栏,因为显示的视图被另一个动画视图(剪切场景样式)覆盖,而我在第一个视图中设置资源并且工具栏需要在所有视图中保持最佳状态。
其实我已经运行到这一点我自己,我能想出了利用initWithCustomView并传递一个UIButton与定义的帧的唯一的事。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
/*
* Insert button styling
*/
button.frame = CGRectMake(0, 0, width, height);
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
否则的UIBarButtonItem只可以设定可惜没height属性width属性。我和initWithCustomView做另一个漂亮的东西是一个按钮,其他像经济指标在工具栏中通过。希望这可以帮助。
创建UIButton
使用首选帧和图像和目标和选择器等。然后使用UIBarButtonItem
的initWithCustomView:
方法和使用的UIButton作为customView。
制作这种简单的三个步骤
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 write实现:
-(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;
}
现在,当你拥有的UIButton在uibarbuttomitem你可以定义所有属性的UIButton像,图像,动作等
你做交第一,但章鱼的答案是更完整。我希望我能分开复选标记。但我没有找到几个自己的帖子有见地的,给他们应有的给予好评。 – Mytheral