iphone iphone鍵盤黑色 更改UIBarButtonSystemItemCancel的顏色




iphone鍵盤黑色 (3)

如果我使用UIBarButtonSystemItemCancel,它的顏色設置為導航欄的顏色。 但是,在照片應用程序中,“取消”按鈕顯示為藍色背景。 我怎樣才能設置UIBarButtonSystemItemCancel有一個藍色的背景?


你可以使用圖像作為按鈕圖像

UIImage *buttonImage = [UIImage imageNamed:@"image.png"];

//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];


//create a UIBarButtonItem with the button as a custom view
//UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];

[button addTarget:self action:@selector(clickActionItem:) forControlEvents:UIControlEventTouchUpInside];

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




self.navigationItem.rightBarButtonItem = rightBarButtonItem;

將NavigationController.navigationBar.barStyle設置為UIBarStyleBlackTranslucent

theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

按鈕默認是藍色的。


有比使用圖像更好的方法。 可以將UISegmentedControl配置為像UIBarButtonItem一樣,並且UISegmentedControl具有tintColor屬性。

UISegmentedControl *button = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:itemTitle, nil]] autorelease];
    button.momentary = YES;
    button.segmentedControlStyle = UISegmentedControlStyleBar;
    button.tintColor = color;
    [button addTarget:theTarget action:selector forControlEvents:UIControlEventValueChanged];

    UIBarButtonItem *removeButton = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

我建立了一個UIBarButtonItem類來完成這個任務。





uinavigationitem