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