簡體   English   中英

iPhone SDK:UIBarButtonItem不顯示邊框

[英]iPhone SDK: UIBarButtonItem is not displaying border

我有一個UIToolbar,我試圖在其上放置一些自定義UIBarButtonItems。 但是,當我使用下面的代碼時,按鈕顯示沒有邊框。

    UIImage *cameraRollButtonImage = [UIImage imageNamed:@"Flash.png"];
    UIButton *cameraRollButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [cameraRollButton setImage:cameraRollButtonImage forState:UIControlStateNormal];
    cameraRollButton.frame = CGRectMake(0.0, 0.0, cameraRollButtonImage.size.width, cameraRollButtonImage.size.height);

    // Initialize the UIBarButtonItem
    cameraRollButtonItem = [[UIBarButtonItem alloc] initWithCustomView:cameraRollButton];
    [cameraRollButtonItem setStyle:UIBarButtonItemStyleBordered];

    //Add the Buttons to the toolbar
    NSArray *toolbarItems = [NSArray arrayWithObject:cameraRollButtonItem];
    [self.cameraTabBar setItems:toolbarItems];

這顯示按鈕就好了,但是沒有按鈕邊框(就像標准的UIBarButtonItem )。 所以行[cameraRollButtonItem setStyle:UIBarButtonItemStyleBordered]; 好像什么也沒做。

有人對這個有經驗么?

我希望能夠在設備方向改變時最終旋轉按鈕中的圖像(保持工具欄靜態),所以簡單地將圖像添加到UIBarButtonItem不起作用; 我需要使用customView屬性來使用它。

非常感謝! 布雷特

您是否考慮使用邊框創建自己的按鈕圖像? 您可以將它用作UIButtonbackgroundImage

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setBackgroundImage:_backgroundImage_ forState:UIControlStateNormal];

// So that the button does not gray out when disabled
[button setBackgroundImage:_backgroundImage_ forState:UIControlStateDisabled]; 

[button setImage:_cameraImage_ forState:UIControlStateNormal];

button.frame = CGRectMake(0, 0, 125, 30);

然后,您可以使用帶有initWithCustomView: button initWithCustomView:

這里的PSD文件可能會為您提供如何創建自己的按鈕的概述。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM