我有一個UIButton與圖像的自定義視圖的UIBarButtonItem,我希望有不同的取向不同的UIImage,所以這裏是我的代碼:改變的UIBarButtonItem的UIButton的形象
UIButton * backButton = (UIButton *) ((UIBarButtonItem *) self.navBar_.topItem.leftBarButtonItem).customView;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) && IS_IPAD) {
[backButton setBackgroundImage:[UIImage imageNamed:@"back-landscape.png"] forState:UIControlStateNormal];
[backButton setFrame: CGRectMake(0, 0, 46, 35)];
} else {
[backButton setBackgroundImage:[UIImage imageNamed:@"back-reading.png"] forState:UIControlStateNormal];
[backButton setFrame: CGRectMake(0, 0, 23, 19)];
}
儘管如此,這並不改變UIButton圖像,這是爲什麼?
是啊這工作..但我不得不再次分配一個新的UIButton – adit 2012-03-02 18:01:54
這不會改變UIBarButton它只是創建一個新的 – 2014-06-27 05:50:17