![](/img/trans.png)
[英]UIBarButtonItem setBackButtonTitlePositionAdjustment doesn't work
[英]UIBarButtonItem design change doesn't work the first time but the second
我想更改我的UIBarButtonItem
的設計,並且此代碼有些起作用:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [[UIImage imageNamed:@"header.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
問題在於應用程序第一次加載按鈕的背景圖像不會改變,但是如果我離開視圖並返回,背景就會變成我想要的。 這是什么問題? 我使用情節提要。
若要使用UIAppearance
,應在加載視圖或創建控件之前設置控件的外觀。 如果您以編程方式創建控件,則可以執行以下操作(示例代碼)
[[UIStepper appearance]setTintColor:[UIColor redColor]];
UIStepper *stepper = [[UIStepper alloc]init];
[self.view addSubview: stepper];
或嘗試在application didFinishLaunchingWithOptions
設置外觀。
從UIAppearance.h
要為包含在容器類的實例中的類的實例或層次結構中的實例自定義外觀,請對適當的外觀代理使用+ appearanceWhenContainedIn:。 例如:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:myNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setTintColor:myToolbarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], [UIPopoverController class], nil] setTintColor:myPopoverToolbarColor];
在初始化課程之前,請在您的課程之外調用代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.